greghendershott / rackjure

Provide a few Clojure-inspired ideas in Racket. Where Racket and Clojure conflict, prefer Racket.
BSD 2-Clause "Simplified" License
236 stars 17 forks source link

Function literals should work in REPLs, too #45

Closed aBathologist closed 9 years ago

aBathologist commented 9 years ago

I'm receiving an error *only with the reader function literals. Everything else is working swell (lots of fun!). This is with Racket version 6.1 running on OS X Mavericks, in DrRacket:

> (map #λ(+ % 1) '(1 2 3))
read: bad syntax `#λ'

> (#lambda(apply list* % %&) 1 '(2 3))
read: bad input: `#lam'

In emacs, with racket-mode, I get the following

20140902.rkt> (map #λ(+ % 1) '(1 2 3))
; stdin::10592: read: bad syntax `# '
; Context:
;  ~/.emacs.d/elpa/racket-mode-20140828.1404/cmds.rkt:28:2
20140902.rkt> ; %: undefined;
;  cannot reference an identifier before its definition
;   in module: "~/myracket/studies/dailyprogrammer/20140902.rkt"
20140902.rkt> '(1 2 3)
20140902.rkt> ; stdin::10610: read: unexpected `)'
; Context:
;  ~/.emacs.d/elpa/racket-mode-20140828.1404/cmds.rkt:28:2

Let me know if I can do anything to help! Or if it looks like a problem just on my end.

greghendershott commented 9 years ago

To make sure I understand, you're experiencing this only in REPLs? But it works fine in a source file that has #lang rackjure at the top?

If so, the answer is that I don't know if/how it is possible for a REPL to use a different readtable automatically. You'll need to tell it. For example in racket-mode's *Racket REPL*:

> (require rackjure/lambda-reader)
> (current-readtable lambda-readtable)
> (map #λ(+ % 1) '(1 2 3))
'(2 3 4)

So that works. Unfortunately, the next time you do Run F5, this will get blown away. As a work-around you could temporarily put the (require rackjure/lambda-reader) and (current-readtable lambda-readtable) in that source file. (Using #lang rackjure effectively does this for you, for the source file. Putting this in the source file is just a work-around for making it take effect in the REPL, too.)

I don't feel like this is a really satisfying answer for you. Maybe there is something I am overlooking about how to make this more automatic.

aBathologist commented 9 years ago

Ah! I'm afraid the problem is that I'm just know too little! I wasn't aware of this discrepancy between the REPL read table and that of the source file using #lang rackjure. Had I known, I wouldn't have mentioned it! Sorry for the bother, and thanks very much for the clarification. I don't even need the reader function in the REPL, but your solution is completely satisfactory for my purposes! It's a very pleasant bit of sugar.

Thanks heaps for racket-mode and, again, I'm sorry for the bother.

greghendershott commented 9 years ago

No worries at all -- I'm glad you reported this. It's completely reasonable to expect this to "just work" in the REPL, too. I wish it did. I just don't understand how to make it do so.

AlexKnauth commented 9 years ago

Would it make sense to modify #%module-begin to put the

(require rackjure/lambda-reader)
(current-readtable lambda-readtable)

in the module body for you? Edit: or maybe this would be better:

(require rackjure/lambda-reader)
(current-readtable (make-lambda-readtable (current-readtable)))

Further Edit: Or it would be better to use either a configure-runtime submodule or the #:language-info option and a runtime-config.rkt

AlexKnauth commented 9 years ago

@aBathologist this should work now if you update

aBathologist commented 9 years ago

@AlexKnauth thanks!