Can't run DrRacket or gracket 7.0 - racket
When I open DrRacket.app v7.0 on OSX 10.7.5, I get this error message:
LSOpenURLsWithRole() failed with error -10810 for the file /Applications/Racket v7.0/DrRacket.app.
Running drracket from the command line yields some more detail:
ffi-lib: couldn't open "/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics.dylib" (dlopen(/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics.dylib, 6): image not found)
context...:
"/Applications/Racket v7.0/share/pkgs/gui-lib/mred/private/wx/cocoa/utils.rkt": [running body]
for-loop
run-module-instance!125
for-loop
[repeats 1 more time]
run-module-instance!125
for-loop
[repeats 1 more time]
run-module-instance!125
for-loop
[repeats 1 more time]
run-module-instance!125
do-dynamic-require5
"/Applications/Racket v7.0/share/pkgs/gui-lib/mred/private/wx/platform.rkt": [running body]
for-loop
run-module-instance!125
...
Any suggestions for what I should try?
I figure that the problem is most likely that I'm running an old version of OSX. CoreGraphics was introduced in 10.8. I've looked for documentation on what OS versions each version of Racket requires, and haven't yet found anything. Does anyone know where it is?
Matthew Flatt kindly answered my question on the Racket github. DrRacket and gracket in RacketĀ 7.0 will indeed run on OSXes earlier than 10.8. To get them to work:
Change line 41 of share/pkgs/gui-lib/mred/private/wx/cocoa/utils.rkt to:
(define cg-lib (ffi-lib (format "/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics") #:fail (lambda () #f)))
In share/pkgs/gui-lib/mred/private/wx/cocoa/queue.rkt, change this line:
(define-cg CGEventTapCreate (_fun _uint32 _uint32 _uint32 _uint64
(_fun #:atomic? #t
#:keep mb-detect-box
_pointer _uint32 _id _pointer -> _id)
_pointer
-> _pointer))
to:
(define-cg CGEventTapCreate (_fun _uint32 _uint32 _uint32 _uint64
(_fun #:atomic? #t
#:keep mb-detect-box
_pointer _uint32 _id _pointer -> _id)
_pointer
-> _pointer) #:fail (lambda () #f))
and this line:
(define-cg CGEventGetLocation (_fun _pointer -> _NSPoint))
to:
(define-cg CGEventGetLocation (_fun _pointer -> _NSPoint) #:fail (lambda () #f))
These changes remove the dependency on CoreGraphics.
Related
How to loop through dates in Racket?
I want to loop through dates from the current date to some stop date, like the following example in Python: import datetime def count_dates(stop_date): step = datetime.date.today() while step >= stop_date: yield step step = step - datetime.timedelta(days=1) def main(): for step in count_dates(datetime.date(2018, 1, 1)): print(step.isoformat()) I don't see any date calculation functions in Racket, however. How can this be done?
If you want to use racket/date, you can accomplish your goal with find-seconds, seconds->date, current-seconds, and a simple arithmetic: #lang racket (require racket/date racket/generator) (define 1day (* 60 60 24)) (define (count-dates year month day) (define target (find-seconds 0 0 0 day month year)) (in-generator (let loop ([current (current-seconds)]) (when (>= current target) (yield (seconds->date current)) (loop (- current 1day)))))) (date-display-format 'iso-8601) (for ([dt (count-dates 2019 2 1)]) (displayln (date->string dt))) This outputs: 2019-02-11 2019-02-10 2019-02-09 2019-02-08 2019-02-07 2019-02-06 2019-02-05 2019-02-04 2019-02-03 2019-02-02 2019-02-01 That is, from today (Feb 11, 2019) to Feb 1, 2019. You can also use gregor or srfi-19 which are alternative date libraries that have a notion of time duration/difference.
Here is how you can do it using the date arithmetic provided by gregor. Specifically the +days and -days functions are helpful here: #lang racket (require gregor racket/generator) ;; Date -> [Sequenceof Date] (define (count-dates stop-date) (in-generator (let loop ([step (today)]) (when (date>=? step stop-date) (yield step) (loop (-days step 1)))))) (for ([step (count-dates (date 2018 1 1))]) (displayln (date->iso8601 step))) And if you need something more general than "some number of days", there's also functions like +date-period and -date-period.
Run DrRacket plugin body only after all plugins initialized, error: phase2: can only be called in phase: 'init-complete
I'm trying to make a small drracket plugin that prints the definitions text reference object to the console on start up. The code I have at the moment is: #lang racket/unit (require drracket/tool) (import drracket:tool^) (export drracket:tool-exports^) (define (phase1) (void)) (define (phase2) (define def (drracket:get/extend:get-definitions-text)) (writeln def)) However, when I install this plugin and start up DrRacket, I get the following error (full message at bottom of post): phase2: can only be called in phase: 'init-complete Which makes sense. Looking at the docs for drracket:get/extend:extend-unit-frame, which is used by drracket:get/extend:get-definitions-text say: Once this function is called, drracket:get/extend:extend-unit-frame raises an error, disallowing any more extensions. So, I'm guessing that phase2 is not late enough to assume that all other plugins are initialized. Unfortunately, there doesn't seem to be any insertion points where I can run the code later than phase2. (If, for example, I just put it in the body of the unit, it will run before phase1 or phase2.) So, where is the appropriate place to to run drracket:get/extend:get-definitions-text? Complete error message: Error in phase 2 for tool #<path:/Users/leif/test/dplugpkg/tool.rkt>; #f phase2: can only be called in phase: 'init-complete context...: /Users/leif/rsrc/drracket/drracket/drracket/private/unit.rkt:528:6: get-definitions-text% /Users/leif/rsrc/drracket/drracket/drracket/private/get-extend.rkt:119:0: get-base-definitions-text% /Users/leif/rsrc/drracket/drracket/drracket/private/get-extend.rkt:69:2: get-built /Users/leif/racket/racket/collects/racket/contract/private/arrow-higher-order.rkt:361:33 /Users/leif/test/dplugpkg/tool.rkt:20:0: phase2 .../more-scheme.rkt:261:28 [repeats 23 more times] /Users/leif/rsrc/drracket/drracket/drracket/private/tools.rkt:432:0: run-phases .../racket/unit.rkt:998:20 "/Users/leif/rsrc/drracket/drracket/drracket/tool-lib.rkt": [running body] temp37_0 for-loop run-module-instance!125 "/Users/leif/rsrc/drracket/drracket/drracket/private/drracket-normal.rkt": [running body] temp37_0 for-loop ... instantiate: contract violation expected: class? given: #f context...: /Users/leif/rsrc/drracket/drracket/drracket/private/unit.rkt:1402:4 /Users/leif/racket/racket/collects/racket/private/class-internal.rkt:3554:0: continue-make-object /Users/leif/rsrc/drracket/drracket/drracket/private/module-language.rkt:1578:4 /Users/leif/racket/racket/collects/racket/private/class-internal.rkt:3554:0: continue-make-object /Users/leif/rsrc/drracket/drracket/drracket/private/debug.rkt:1907:4 /Users/leif/racket/racket/collects/racket/private/class-internal.rkt:3554:0: continue-make-object [repeats 2 more times] /Users/leif/rsrc/drracket/drracket/drracket/private/module-language-tools.rkt:88:4 /Users/leif/racket/racket/collects/racket/private/class-internal.rkt:3554:0: continue-make-object /Users/leif/rsrc/drracket/drracket/drracket/private/syncheck/gui.rkt:2035:6 /Users/leif/racket/racket/collects/racket/private/class-internal.rkt:3554:0: continue-make-object /Users/leif/Library/Racket/planet/300/development/cache/jowalsh/code-coverage.plt/1/4/tool.rkt:25:6 /Users/leif/racket/racket/collects/racket/private/class-internal.rkt:3554:0: continue-make-object [repeats 1 more time] /Users/leif/rsrc/drracket/drracket/gui-debugger/debug-tool.rkt:1156:6 /Users/leif/racket/racket/collects/racket/private/class-internal.rkt:3554:0: continue-make-object ... leif#FATT ~/test/dplugpkg $ drracket Error in phase 2 for tool #<path:/Users/leif/test/dplugpkg/tool.rkt>; #f phase2: can only be called in phase: 'init-complete context...: /Users/leif/rsrc/drracket/drracket/drracket/private/unit.rkt:528:6: get-definitions-text% /Users/leif/rsrc/drracket/drracket/drracket/private/get-extend.rkt:119:0: get-base-definitions-text% /Users/leif/rsrc/drracket/drracket/drracket/private/get-extend.rkt:69:2: get-built /Users/leif/racket/racket/collects/racket/contract/private/arrow-higher-order.rkt:361:33 /Users/leif/test/dplugpkg/tool.rkt:20:0: phase2 .../more-scheme.rkt:261:28 [repeats 23 more times] /Users/leif/rsrc/drracket/drracket/drracket/private/tools.rkt:432:0: run-phases .../racket/unit.rkt:998:20 "/Users/leif/rsrc/drracket/drracket/drracket/tool-lib.rkt": [running body] temp37_0 for-loop run-module-instance!125 "/Users/leif/rsrc/drracket/drracket/drracket/private/drracket-normal.rkt": [running body] temp37_0 for-loop ... instantiate: contract violation expected: class? given: #f context...: /Users/leif/rsrc/drracket/drracket/drracket/private/unit.rkt:1402:4 /Users/leif/racket/racket/collects/racket/private/class-internal.rkt:3554:0: continue-make-object /Users/leif/rsrc/drracket/drracket/drracket/private/module-language.rkt:1578:4 /Users/leif/racket/racket/collects/racket/private/class-internal.rkt:3554:0: continue-make-object /Users/leif/rsrc/drracket/drracket/drracket/private/debug.rkt:1907:4 /Users/leif/racket/racket/collects/racket/private/class-internal.rkt:3554:0: continue-make-object [repeats 2 more times] /Users/leif/rsrc/drracket/drracket/drracket/private/module-language-tools.rkt:88:4 /Users/leif/racket/racket/collects/racket/private/class-internal.rkt:3554:0: continue-make-object /Users/leif/rsrc/drracket/drracket/drracket/private/syncheck/gui.rkt:2035:6 /Users/leif/racket/racket/collects/racket/private/class-internal.rkt:3554:0: continue-make-object /Users/leif/Library/Racket/planet/300/development/cache/jowalsh/code-coverage.plt/1/4/tool.rkt:25:6 /Users/leif/racket/racket/collects/racket/private/class-internal.rkt:3554:0: continue-make-object [repeats 1 more time] /Users/leif/rsrc/drracket/drracket/gui-debugger/debug-tool.rkt:1156:6 /Users/leif/racket/racket/collects/racket/private/class-internal.rkt:3554:0: continue-make-object ...
Both phase1 and phase2 certainly happen too early to use drracket:get/extend:get-definitions-text. You can however insert your own hook that will run on the creation of a new definitions-text object. You do this with the appropriately named drracket:get/extend:extend-definitions-text, which takes a mixin (a function of type Class -> Class). By putting the call in the body of the class, you can ensure that not only all plugins will be instantiated, but that it will be called for every new definitions text DrRacket makes. Your code will look something like this: (define (def-mixin super%) (class super% (super-new) (define the-def-text (drracket:get/extend:get-definitions-text)) (writeln the-def-text))) Of course, by this point that is a reference to this mixins own class, and so using this% instead produces an identical plugin: (define (def-mixin super%) (class super% (super-new) (define the-def-text this%) (writeln the-def-text))) (drracket:get/extend:extend-definitions-text def-mixin) Putting everything together, you end up with: #lang racket/unit (require drracket/tool) (import drracket:tool^) (export drracket:tool-exports^) (define (def-mixin super%) (class super% (super-new) (writeln this%))) (define (phase1) (void)) (define (phase2) (void)) (drracket:get/extend:extend-definitions-text def-mixin)
Getting access to Coq's rich XML-like AST output
In older versions of Coq (< 8.5), the main coqtop process would interchange data with IDEs using strings. This was supposedly recently changed - how does one query the richer XML-like structure representing ASTs? Use case: I would like to interpret whatever Coq computes in a different way - that is, I need its results after performing operations (such as invoking tactics) in a form that's not string that I need to parse.
Note: this answer has been edited to make it up to date The only reasonable option as of end of 2018 is SerAPI, a Coq language server that supports full serialization of Coq documents. Using SerAPI you can get a full representation of any Coq document or internal structure: $ rlwrap sertop --printer=human (Add () "Lemma u n : n + 0 = n.") > (Answer 0 (StmAdded 2 (...) NewTip)) (Query ((sid 2)) Ast) > (Answer 1(ObjList > ((CoqAst > (VernacStartTheoremProof Lemma > ((((((Id u)) ())) > (((LocalRawAssum > (((Name (Id n)))) > (Default Explicit) > (CHole () IntroAnonymous ()))) > (CNotation > "_ = _" > (((CNotation > "_ + _" > (((CRef > (Ident > (Id n))) > ()) > (CPrim > (Numeral (Ser_Bigint 0)))) > () ())) > (CRef > (Ident > (Id n))) > ())) > () ())) > ()))) > false))))) Note that SerAPI is experimental software and I am the main author.
emacs: slime-repl hang if using read() or read-line() function
I am using Emacs 24.3.1 on Ubuntu 14.04, slime-20160402.549, GNU CLISP 2.4. Whenever i use read() or read-line() function in slime-repl, it will freeze after one or two input characters (e.g. "wa"), ; SLIME 2016-04-02 CL-USER> (read) wa Trying C-g it shows the error below: Debugger entered--Lisp error: (quit) accept-process-output(nil 0.01) #[0 "\306\307!\306\310!\211\302L\266\211\211\300L\266\311\312J\301#\313\314\315\316\317D\316\nD\316\fD\320\257E\257!\266\321\322\323 \322\262\322\262\324!\325=\204J slime-eval((swank:simple-completions "wa" (quote "COMMON-LISP-USER"))) slime-simple-completions("wa") ac-source-slime-simple-candidates() ac-candidates-1(((init . ac-slime-init) (candidates . ac-source-slime-simple-candidates) (candidate-face . ac-slime-menu-face) (selection-face . ac-slime-selection-face) (prefix . slime-symbol-start-pos) (symbol . "l") (document . ac-slime-documentation) (match . ac-source-slime-case-correcting-completions))) ac-candidates() ac-update(t) ac-show-menu() apply(ac-show-menu nil) ... This problem does not happen in clisp REPL on command line. Any helps?
Best way to read (MATLAB) structures from a text file in Clojure / Incanter
I exported my matlab structs to text files so that I can read them in clojure. I have a text file like: name Ali age 33 friends-ages 30 31 25 47 know I can read this file, but what's the clojure way to convert it into something like: (def person1 {:name "Ali" :age 33 :friends-ages [30 31 25 47]}) or lets make it easier: name Ali age 33 to: (def person1 {:name "Ali" :age 33})
Assuming each file has a single record, (defn parse [f] (let [[_ name _ age _ & friends] (.split (slurp f) "\n")] {:name name :age age :friends (map read-string friends)})) (parse "../../../Desktop/t.txt") you get, {:name "Ali", :age "33", :friends-ages (30 31 25 47)}
I guess you would need to manually do this conversion from text file (which isn't in any standard serialization formats) to the required set format. If possible, I would suggest that you should extract the MATLAB data in JSON format and that would be easy to read in clojure using the json library.
Here's a solution for your easier problem: (ns example (:require [clojure.string :as str])) (def input "name\nAli\nage\n33\n") ; you'd get this by reading the file (defn process [data] (->> (str/split data #"\n") (partition 2) (map (fn [[k v]] [(keyword k) (try (Integer/valueOf v) (catch NumberFormatException _ v))])) (into {}))) (prn (process input)) The full problem requires better specification of the format: how do you know that the list of ages is done?
I ended up writing an .m file to export my .mat files to text, then imported them by something like the following: (use '[clojure.string :only (split join)]) (defn kv [[k v]] [(keyword k) v]) (let [a (split (slurp (java.io.FileReader. fileName)) #"\n")] (def testNeuron (into {} (map kv (partition 2 a))))) Thanks to the answers by Hamza and Jouni. The actual code is more like this: (def dataPath "/home/ali/Dropbox/Projects/Neurojure/") (def testFileName "dae062.c1.cylinder.DID.txt") (defn kv [[k v]] [(keyword k) (if (< 0 (count (re-seq #"\d\d\d\dSpikes|\d\d\d\dOcodes|\d\d\d\dOSpikes" k))) (into [] (map (fn [x] (Integer/valueOf x)) (split v #","))) (try (Integer/valueOf v) (catch NumberFormatException _ v)))]) (let [a (split (slurp (java.io.FileReader. (str dataPath testFileName))) #"\n")] (def testNeuron (into {} (map kv (partition 2 a))))) and the converted data file looks like this: ConvertDate 18-Nov-2011 Name /bgc/data/dae/062/dae062.mat frameperiod 83.2500000037253 Spike2Version 1.27 unstored 167 rfstr cm=rf-3.10,9.61:0.00x0.00,-135deg pe20 -2.0,-3.0 fx=0.00,fy=0.00cm=rf-3.10,9.61:0.00x0.00,-135deg pe20 -2.0,-3.0 fx=0.00,fy=0.00 rf -3.1,9.61,0,0,-135,20,-2,-3,0,0 trange 47371169.75,100193717.5 psych 1 rc 0 Options expname cylinder.dxXIdD Start 94745610.75 End 100193717.5 Area MT Ex perimenter Ali Trial=>0001Start 47377343 Trial=>0001TrialStart 47377343 Trial=>0001End 47397224.25 Trial=>0001dur 19881.2500000075 Trial=>0001uStim 0 Trial=>0001op 40980 Trial=>0001Trial 1860 Trial=>0001id 15897 Trial=>0001Startev 47377149.5 Trial=>0001serdelay -46.25 Trial=>0001bstimes 47377195.75 Trial=>0001delay 147.25 Trial=>0001TrueEnd 47397224.25 Trial=>0001CorLoop 0 Trial=>0001dx 0 Trial=>0001Spikes -1402,-1232,1577,1931,2165,2222,2478,2773,2903,3229,3745,3820,4071,4588,4920,5141,5752,6440,6490,6664,6770,7042,7958,8081,8307,8622,8732,9021,9082,9343,9619,9695,9877,10357,10668,10943,11105,11364,11720,12272,12499,12762,12907,13621,14121,14351,14542,14588,15104,15420,15501,16331,16596,16843,17476,17698,17996,18169,18401,18532,18706,19029,19081,19418,19603,19750,20222 Trial=>0001count 65 Trial=>0001OptionCode +do+aa+sq+72+se+fc+fb+ap+wt+cf+ws+ts+sw+bw+cs+2a+bm+gm+x2+sp+da+ao+cS+C3+CF Trial=>0001me 0 Trial=>0001OSpikes -1976,-1802,-1423,-1360,-1268,-1248,-1140,-244,-220,-164,632,681,730,760,779,786,867,879,924,1062,1161,1252,1268,1431,1533,1632,1946,2210,2235,2273,2285,2296,2305,2496,2532,2541,2732,2787,2806,2822,2840,3095,3292,3431,3598,3614,3837,4100,4482,4504,4515,4651,4768,4794,4936,5020,5160,5184,5300,5314,5710,5764,6431,6453,6471,6553,6561,6584,6791,7018,7124,7880,7905,7940,7968,8011,8315,8330,8352,8568,8666,8748,8756,8766,8797,8836,9038,9297,9328,9360,9471,9632,9639,9721,9939,10196,10363,10375,10387,10410,10931,10953,10969,10986,11038,11118,11135,11405,11692,12018,12163,12258,12492,12512,12525,12884,12899,12919,13156,13183,13638,13674,13842,13988,14110,14298,14310,14321,14606,14617,15124,15132,15150,15289,15341,15620,16293,16305,16342,16364,16441,16604,16692,16932,16997,17059,17086,17210,17368,17495,17626,17639,17651,17677,17718,18013,18247,18353,18553,18691,18722,18887,18941,19438,19774,19938,19959,19967,20004,20240,20306,20500,20623 Trial=>0002Start 47406914 Trial=>0002TrialStart 47406914 Trial=>0002End 47426795.25 Trial=>0002dur 19881.2499999925 ...