Hello everyone,
I'm using Gambit on an iPod Touch, and have run into a small hitch when trying to write a macro. The hitch is that I have no way of typing in a ` on the device. It's just not on the keyboard.
I realize that I could use (quasiquote a) instead, but I'm really kind of lazy, and would far prefer to write something like $(a b c). I asked Guillaume Cartier on IRC, and he suggested that it was non-standard but possible. He also mentioned it was undocumented, and so instead of trolling through the code, I thought it might be worth while to ask here first for some pointers.
Are there any examples of adding syntax like this to Gambit available? Do I need to edit and recompile the interpreter, or can I hook in to the reader somehow?
(I'ld even live with ($ a b c), but I can't seem to get that working either.)
Thanks, Blake.
Afficher les réponses par date
Date: Fri, 01 Feb 2008 16:07:42 -0500 From: Blake Winton bwinton@latte.ca
(I'ld even live with ($ a b c), but I can't seem to get that working either.)
Try
(define-syntax $ (syntax-rules () (($ x) (quasiquote x)))),
or
(define-macro ($ x) (list 'quasiquote x)).
(This is subtly different from what I am guessing you asked for, but more general: I am guessing that by ($ a b c) you meant `(a b c), but in that case you have no way to write `a for something that is not a list (e.g., a vector). This may not matter to you -- modifying the above macros to do that is left as a trivial exercise for the reader.)
Alteration of the $ character in the readtable is generally a bad idea, because there may be many legitimate symbols that begin with it, which you would be left with no way to name.
Alternatively, is there really no way for you to enter a backtick, or to translate the $ key stroke to a ` character? If you used $, your code would be very confusing for anyone who tried to read it.
Taylor R Campbell wrote:
(I'ld even live with ($ a b c), but I can't seem to get that working either.) Try (define-syntax $ (syntax-rules () (($ x) (quasiquote x)))),
*** ERROR IN (console)@1.32 -- Ill-formed expression
(define-macro ($ x) (list 'quasiquote x)).
This seems fine, but...
($ a b ,(+ 3 2) c) *** ERROR IN (console)@6,1 -- Ill-formed special form: $
(This is subtly different from what I am guessing you asked for, but more general: I am guessing that by ($ a b c) you meant `(a b c), but in that case you have no way to write `a for something that is not a list (e.g., a vector). This may not matter to you -- modifying the above macros to do that is left as a trivial exercise for the reader.)
Oh, wait: ($ (a b ,(+ 1 2) c)) (a b 3 c) Okay, that's cool. Just to check, would the modification be: (define-macro ($ . x) (cons 'quasiquote x)) ? Nope. *** ERROR IN (console)@10.1 -- Ill-formed special form: quasiquote
I'll play around with that some more.
Alteration of the $ character in the readtable is generally a bad idea, because there may be many legitimate symbols that begin with it, which you would be left with no way to name.
I'm open for suggestions for other characters. € perhaps?
Alternatively, is there really no way for you to enter a backtick, or to translate the $ key stroke to a ` character? If you used $, your code would be very confusing for anyone who tried to read it.
Yeah, there really isn't. I expect my macro code to be a little confusing, but since I'm only going to be programming throw-away scripts on the device, I'm hoping it won't really affect anyone.
Alex Shinn wrote:
Blake> Hello everyone, I'm using Gambit on an iPod Touch, and have Blake> run into a small hitch when trying to write a macro. The Blake> hitch is that I have no way of typing in a ` on the device. Blake> It's just not on the keyboard.
That's funny... ` is the only printable ASCII character it lacks. It has the pound, euro and yen signs, and several international keyboards, and no possible way to input `.
Yeah, go figure, eh? It's like they're trying to drive everyone to Python (or just away from APL ;).
But, how can you possibly code on that thing anyway? Apart from the pain of the horrid keyboard, there's the fact that you have no editor support. I would just ssh in from a real terminal, or cross-compile.
Ya know, I'm getting used to the keyboard quicker than I thought I would, and I've got vi on it, and there's a graphical editor, as well. When I'm at my desk at work, or at home, I do ssh in, but when my wife and I are watching TV (which doubles as the computer monitor), or when I'm on the subway, it's nice to be able to still hack.
And finally, Marc Feeley wrote:
Beware, fiddling with Gambit's internal routines will void the warranty...
Heh. I think I've already done that by porting it to the iPhone in the first place. :)
(begin
(##readtable-char-class-set! (current-readtable) #\$ ;; the character to dispatch on #t ;; this character is a delimiter (lambda (re c) (##read-quotation re #\`))) ;; handler #f)
$(1 ,(+ 2 3) 4)
(1 5 4)
I just tried to type this in on the device, but it seems to have a ` in the middle of it. :P On the plus side, I ssh-ed in, and saved that as .gambcini and then, on the device,
$(1 ,(+ 2 3) 4)
(1 5 4)
Sweetness!
Thank you all for your help, Blake.
On 1-Feb-08, at 11:25 PM, Blake Winton wrote:
And finally, Marc Feeley wrote:
Beware, fiddling with Gambit's internal routines will void the warranty...
Heh. I think I've already done that by porting it to the iPhone in the first place. :)
Naw, that only voids the iPhone's warranty.
(begin
(##readtable-char-class-set! (current-readtable) #$ ;; the character to dispatch on #t ;; this character is a delimiter (lambda (re c) (##read-quotation re #`))) ;; handler #f)
$(1 ,(+ 2 3) 4)
(1 5 4)
I just tried to type this in on the device, but it seems to have a ` in the middle of it. :P On the plus side, I ssh-ed in, and saved that as .gambcini and then, on the device,
Sorry about that... just replace #` by #\u0060 .
Marc
On 1-Feb-08, at 4:07 PM, Blake Winton wrote:
Hello everyone,
I'm using Gambit on an iPod Touch, and have run into a small hitch when trying to write a macro. The hitch is that I have no way of typing in a ` on the device. It's just not on the keyboard.
I realize that I could use (quasiquote a) instead, but I'm really kind of lazy, and would far prefer to write something like $(a b c). I asked Guillaume Cartier on IRC, and he suggested that it was non-standard but possible. He also mentioned it was undocumented, and so instead of trolling through the code, I thought it might be worth while to ask here first for some pointers.
Are there any examples of adding syntax like this to Gambit available? Do I need to edit and recompile the interpreter, or can I hook in to the reader somehow?
(I'ld even live with ($ a b c), but I can't seem to get that working either.)
Beware, fiddling with Gambit's internal routines will void the warranty...
(begin
(##readtable-char-class-set! (current-readtable) #$ ;; the character to dispatch on #t ;; this character is a delimiter (lambda (re c) (##read-quotation re #`))) ;; handler #f)
$(1 ,(+ 2 3) 4)
(1 5 4)
Marc
"Blake" == Blake Winton bwinton@latte.ca writes:
Blake> Hello everyone, I'm using Gambit on an iPod Touch, and have Blake> run into a small hitch when trying to write a macro. The Blake> hitch is that I have no way of typing in a ` on the device. Blake> It's just not on the keyboard.
That's funny... ` is the only printable ASCII character it lacks. It has the pound, euro and yen signs, and several international keyboards, and no possible way to input `.
But, how can you possibly code on that thing anyway? Apart from the pain of the horrid keyboard, there's the fact that you have no editor support. I would just ssh in from a real terminal, or cross-compile.