[racket] there must be function right after parenthesis?

From: 김태윤 (kty1104 at gmail.com)
Date: Sat Oct 30 04:38:30 EDT 2010

wow.. thank you for your very kind explain
it is very helpful and I notice how do they works
thanks a lot!

2010/10/29 synx <plt at synx.us.to>

> Hash: SHA1
> Racket is different from most languages in that it has a flexible
> syntax. That means you can define new syntactical constructs, even
> entirely new languages that barely resemble the original (see Honu)
> (module weird racket/base
>  (define-syntax-rule (weird (a) (b) (c))
>    (list a b c))
>  (weird ("this") ("is") ("weird"))
> ...will simplify down to (list "this" "is" "weird") and not be incorrect
> even though the strings are right next to the parentheses.
> (module weird2 racket
>  (define-syntax (weird2 form)
>    (syntax-case form ()
>      ((_ (((a))))
>       #'23)))
> (weird2 (((1))))
> ...will simplify down to 23, ignoring all the parentheses in there and
> even the 1!
> You can think of the (procedure argument argument argument...) thing as
> a default syntax for the racket language and the racket/base language.
> *Most* of the time you can only put a procedure on the left of such a
> parenthetical statement, since in *most* syntaxes that instructs to
> apply the right arguments to the leftmost procedure. Except for a *very*
> few examples (like you noticed with instantiate), and except for any
> weird stuff you provide yourself, that is what you can expect from racket.
> Another more commonly used exception is the let syntax.
> (module let-example racket/base
>  (let ((a 1) (b 2))
>    (list a b)))
> ... produces (list 1 2). If you could never put anything on the left
> side of a parenthetical statement except a procedure, then the above
> syntax would produce an error, since neither a nor b are procedures.
> ((a 1) (b 2)) by itself produces an error, since by default it assumes
> a and b are procedures. But within (let ...) it does not produce an
> error, because the let syntax is different from the normal syntax.
> ...I always use "new" not "instantiate," myself. It's a little jarring
> to read the syntaxof instantiate for me.
> (define frame (new frame% (label "Example"))
> ...is much preferable for me. It's really a matter of opinion at that
> point though. "label" isn't a procedure either, since new itself has its
> own syntax, but it just looks nicer to me.
> > and I don't understand how such a code like
> > ((func arg) arg2) works too.
> In racket, functions (or "procedures") are 1st class. That means they
> can be stored in variables, applied as arguments, and returned from
> other procedures. When you see ((func arg) arg2) what you can deduce is
> either it produces an error, or else (func arg) must return a procedure,
> to which arg2 is then applied.
> (module bb racket/base
>  (define plus +)
>  (define (doubleplus n) +)
>  (list (plus 2 4) ((doubleplus 'ignored) 2 4) (+ 2 4)))
> ...produces (list 3 3 3). Procedures that return procedures are more
> useful in the sense of /closures/. You can make a procedure that already
> contains information previously known, then apply more arguments later
> to get the end result:
> (module name racket/base
>  (define (make-show-name last)
>    (define (show-name first)
>      (list first last))
>    show-name)
>  (define show-full-name (make-show-name "Smith"))
>  (list (show-full-name "Bob") (show-full-name "Alice"))
>  ((make-show-name "Last") "First"))
> You can see the above lets you first specify a last name, then get the
> full name both first and last by repeatedly specifying first names. With
> the ((a "b") "c") syntax, it's just skipping the repeating part, and
> going straight to one single first/last name pair.
> Version: GnuPG v2.0.14 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> F5vvLSSUyPMo5CeedXTA7ObVGM5vqoAo7pK7nmcEmOE5S8QapReYnjGQwWnEueW4
> l6WDapQg8zkaaAZjIyVxOCgwZaoEAlPgwm2B86q8ivJ447xfghyrFv5ifsVXp9Hp
> 1Jqu9m6chfXaMtbv4Vp/frWDLwmIhrDjx7aQoGhiVGUhYYvq9CNkzTrzVhM/I1ib
> +OsvKH3Pg63FxHrQhII29DdYFMfFmTk3uFMjSw1ZI/Cc38F/BAbqogILxKVr9f4f
> Qz7UoR5FWe36vZUdy43VDNxiHlsY0B1clCGSn2duP335KLrwIpuS/GjjQWC4CrE=
> =9Ial
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20101030/fd9c2c2b/attachment.html>

Posted on the users mailing list.