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