The main problem with Racket's macro system (and with other syntax-case systems) is that instead of raw s-expressions you're dealing with syntax objects. This becomes very ugly when identifiers are handled: instead of dealing with plain symbols, you're dealing with these syntax values (called “identifiers” in this case) that are essentially a symbol and some opaque information that represents the lexical scope for its source. In several syntax-case systems this is the only difference from defmacro macros, but in the Racket case this applies to everything — identifiers, numbers, other immediate constants, and even function applications, etc — they are all wrapped with additional information.
Name:
Anonymous2011-04-21 23:21
Macro in LISP.
(defmacro aif (cond then else)
`(let ((it ,cond))
(if it ,then ,else)))
"Macro" in Scheme/Racket.
#lang racket
(require racket/stxparam)
(define-syntax-parameter it (lambda (stx) (raise-syntax-error 'anaphora "missed context" stx)))
(define-syntax-rule (aif cond then else)
(let ([temp cond])
(syntax-parameterize ([it (make-rename-transformer #`temp)])
(if temp then else))))
Name:
Anonymous2011-04-22 1:04
I try to pop in to this forum from time to time and see if there are any newbie questions I can answer or maybe pick-up a few new tricks. Today marks the longest period of time I have seen between perl posts here --- complete month! I would say that perl is dying. It is still useful to know, but it won't be many people's first choice.
I have learned the fundamental difference between perl & php - php is much easier to interlace with html, ie jumping in and out to make life easier. I am finding that perl is no where near as flexible, actually I don't think it's possible, and even if it is, it wouldn't be considered good practise.
Name:
Anonymous2011-04-22 1:42
Good gawd, WRRRRYYYYYYYYYY? :S
srsly?
Whysubject yourself to this? Use a damn GUI editor -- WE HAVE THEM U KNOW? :) :D
Name:
Anonymous2011-04-22 1:43
gedit does a fine job at highlighting most recognized formats! As mattr of fact!!!!
Name:
Anonymous2011-04-22 1:49
racket code isn't data, so you can't really expect much from the language. tsk.
Name:
Anonymous2011-04-22 1:50
is racket even turing-complete?
Name:
Anonymous2011-04-22 1:57
>>8
Does anybody do anything useful with code=data? I've never found any compelling reason to do so.
I hav made a code that made a code that made a code that then simplified somes code that then called Glen Beck who didnt help and then simplified more code in spite of that.
Name:
Anonymous2011-04-22 2:02
instead of raw s-expressions you're dealing with syntax objects.
Such things are good for academy and PhD's.
The main problem with Common Lisp's macro system (and with other define-macro systems) is that instead of syntax objects you're dealing with raw s-expressions. This becomes very ugly when using the macro in a different context than it was defined in: instead of dealing with identifiers, you're dealing with these plain data (called “symbols” in this case) that are essentially an identifier stripped of anything but their name, including the lexical scope for its source. In several define-macro systems this is the only difference from hygienic macros, but in the Common Lisp case this combines with its terrible module system (called “packages”) and lack of phasing (eval-when considered harmful to your mental health) to create a system which is only held together by duct tape and prayer.
C macros = text substitution.
CL macros = sexp substitution. (glorified C macros)
Hygienic macros = sexp/syntax substitution, hygiene only on symbols.
Racket macros = sexp/syntax substitution, everything is a syntax object. You can attach properties and information on every piece of syntax. You can write a fucking type system without completely redefine `define', `let', etc.
>>14
If you think symbols are simple, you obviously don't know CL well-enough. Symbols are a structure having a name, a value, a functional value, a package (which is a collection of collection of symbols), a plist (which is essentially a tag<->value list) at minimum (implementations may have more).
CL's defmacro is available in Racket using (require mzlib/defmacro). I'd strongly advise actually learning Racket's macro system, however, because it allows you to write composable macros that cannot inadvertently capture variables while being able to introduce identifiers as needed.
CL's unhygienic macros are simple to write and understand, but they are not simple to use or compose. Racket's macros are exactly as hard to write as the actual task you're attempting to accomplish: a simple hygienic macro is trivial to write with define-syntax-rules, while a simple unhygienic macro is trivial to write with mzlib/defmacro. It's only when you're trying to do more complex stuff like selectively break hygiene that things get complicated.
DrRacket's macro stepper, incidentally, is very useful for seeing what a macro usage will expand into, and the automatic arrows from identifiers to the macro that introduced them are a life saver.
Name:
Anonymous2011-12-12 13:01
>>28
Just use quasiquote with auto-gensyms, because CL's quasiquote is broken in many ways, that have nothing to do with macros.