Search code examples
lambdaschemelispr5rsgambit

Is there a Macro to use "λ" character as "lambda" in R5RS Scheme?


Is there a Macro to use "λ" character as "lambda" in R5RS Scheme? From here In Gambit "scheme-r5rs" I tried:

(define-syntax λ
  (syntax-rules ()
    ((_ . more) (lambda . more))))

But I keep getting Ill-formed expression error.


Solution

  • You seem to be looking for a reader macro, but I don't think they are standardised in Scheme.

    This works:

    # pu@pumbair: ~  cat test2.scm
    (define-syntax λ
        (syntax-rules ()
           ((_ param body ...) (lambda param body ...))))
    (display ((λ (x y) (+ x y)) 1 2)) (newline)
    (display ((λ () 1))) (newline)
    (display ((λ (a . b) b) 'a 'b 'c)) (newline)
    
    # pu@pumbair: ~  gsi -:s test2.scm
    3
    1
    (b c)