[racket] hack: implicit function arguments

From: Horace Dynamite (horace.dynamite at gmail.com)
Date: Sat Aug 14 14:19:42 EDT 2010

> I think what Jon was referring to is a feature of Scala more like
> Jay's 'scut' macro - you can implicitly create a function by inserting
> an _.  For example:
> _ + 1 in scala is the same as (lambda (x) (+ x 1))

It just seemed like fate that I was reading this thread, whilst
simulatanesouly stumbling across this page on the Internet,

[SOURCE: http://wcp.sdf-eu.org/software/index.html]

Some syntactic sugar for Scsh (or Scheme48).
One of the features in the wish list of Arc that I found cool was the
square bracket sexp that expands to a single argument lambda
expression. So that one can do things like:

(map [/ _ 2] '(2 4 6 8 10))
(cond ((regexp-exec re str) => [match:substring _ 1]) ...)

instead of

(map (lambda (x) (/ x 2)) '(2 4 6 8 10))
(cond ((regexp-exec re str) => (lambda (m) (match:substring m 1))) ...)

Disclaimer: I am not advocating Perl-ish syntactic crypticism. This
has been written just as a funny exercise in Scsh hacking.
Here is a less heretic approach for those using Emacs:

(defun lisp-insert-lambda ()
  "Insert lambda form at point asking for variables."
  (insert "(lambda (" (read-string "Variables: ") ") ")
  (save-excursion (insert ")")))

(add-hook 'scheme-mode-hook
          '(lambda ()
             (local-set-key "\C-cl" 'lisp-insert-lambda)))



Posted on the users mailing list.