Re: sharp-back syntax



In article <1175283293.779691.217500@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
nallen05@xxxxxxxxx wrote:

On Mar 29, 10:23 pm, Barry Margolin <bar...@xxxxxxxxxxxx> wrote:
In article <MaSdnbeOX7C4FZHbnZ2dnUVZ_hGdn...@xxxxxxxxxxxxx>,
r...@xxxxxxxx (Rob Warnock) wrote:



<nalle...@xxxxxxxxx> wrote:
+---------------
| I hate having to type l-a-m-b-d-a over and over again...
| luckily it's easy to add syntax to Lisp:
...
| #`(= ?x 5) => (lambda (?x) (= ?x 5)) ...
| (mapcar #`(> ?x ?y) list1 list2) => ...
+---------------

Yeah, I think we've all done something similar. Myself,
I called it #$ and used shell-like ${digit} as params:

> (mapcar #$(= $1 5) '(1 3 5 7 9))

(NIL NIL T NIL NIL)
> (mapcar #$(* $1 1.085) '(12.34 15 10 25.37))

(13.3889 16.275 10.85 27.52645)
> (mapcar #$(> $1 $2) '(1 2 3 4 5) '(5 4 3 2 1))

(NIL NIL NIL T T)
> (mapcar #$$2 '(1 2 3) '(4 5 6) '(7 8 9))

(4 5 6)

But I use this *only* at the REPL when poking around,
*never* in saved source files...

One problem I can see with this is that they don't nest properly. The
outer one will drill into inner one and see its implicit lambda
variables, and make them into lambda varables for the outer one.

Also, if you have any quoted lists that contain symbols in the same
format as your implicit lambda variables, the reader macro will think
they're variables.

are you talking about mine or Rob's? Mine doesn't actually rewrite any
code, it just wraps it in a "(lambda list-of-implicit-lambda-vars..."
form so QUOTE will behave normally, so will scope...

I'm talking about both versions. You have to walk through the code
looking for the implicit lambda vars, so that you construct the lambda
list. But if there are any quoted symbols that look like your implicit
lambda variables you'll add them to the lambda list. E.g. I'd expect
this:

(mapcar #$(eq $1 '$2) '(a b $2 c))

to generate a "wrong number of arguments" error because it will expand
into:

(mapcar #'(lambda ($1 $2) (eq $1 '$2)) '(a b $2 c))

--
Barry Margolin, barmar@xxxxxxxxxxxx
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
.



Relevant Pages

  • Groebner Basis in Scheme
    ... (lambda (flag item) ... queue (cdr ... flag 'head) (car queue)) ... (define (%cars+cdrs lists) ...
    (comp.lang.scheme)
  • Re: Groebner Basis in Scheme
    ... (lambda (flag item) ... queue (cdr ... flag 'head) (car queue)) ... (define (%cars+cdrs lists) ...
    (comp.lang.scheme)
  • Re: PCL: question about lambda usage
    ... CL-USER> (addl 3) ... Browsing ahead in the book a bit it reiterates the form of lambda as: ... MAPCAR takes a function and 1 or more lists and creates a list of values by applying the function to each input elementin sequence. ...
    (comp.lang.lisp)
  • Re: Lisp Syntax - functions versus data
    ... So you have a problem with your lambda there. ... So what's the quote there for? ... You want to compare lists here, ...
    (comp.lang.lisp)
  • Re: A Moronicity of Guido van Rossum
    ... lambda in Python issue. ... i'm running a project that will code Table in Perl and Python and Java. ... Note Table's power in generating not just flat lists, ... these inline loop constructs are not just for computing numbers ...
    (comp.lang.scheme)