[racket] Macro using eval inside html-template

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Tue Jan 8 13:13:25 EST 2013

Okay, I dug a little bit into Neil's library. From what I can tell, these words don't refer to functions at all. In Neil's library, they are used within the context of a form that 'quotes' these things. Then they are processed in a context where title denotes HTML's title element. So your problem is not macros or eval but a misunderstanding of your library. -- Matthias



On Jan 8, 2013, at 10:02 AM, Philipp Dikmann wrote:

> My function would always get hung up on the unknown identifiers like 'title' or 'math' when it tried to evaluate the expressions passed as arguments -
> but you are right, the macro is not really necessary. I can quote the expressions and use the html-writing module instead, which handles quoted lists.
> I was just looking for ways to achieve a cleaner syntax.
> 
> 
> 
> On 07.01.13 23:20, Matthias Felleisen wrote:
>> I don't see any need for a macro here. Why not use a function that iterates over these 'forms':
>> 
>> (define (expr-iter . form)
>>   (for ((f form))
>>     (case (first f)
>>       ...
>>       [(math) (eval (second f) some-useful-namespace)]
>>       ...)))
>> 
>> 
>> 
>> 
>> 
>> On Jan 7, 2013, at 3:57 PM, Philipp Dikmann wrote:
>> 
>>> Hello Racket-Users,
>>> 
>>> in trying to iterate a series of expressions and evaluating them differently on a case-by-case basis - specifically in the body of a (html-template) - Racket is throwing errors indicating that my expressions end up in the wrong places. In the code below, it appears that + is being interpreted as an HTML element name; am I messing up expansion time and run time?
>>> 
>>> 
>>> #lang racket
>>> 
>>> (require (planet neil/html-template:2:2))
>>> 
>>> (define-syntax-rule (expr-iter form ...)
>>>  (begin
>>>    (case (car 'form)
>>>      [(title) (display (cadr 'form))]
>>>      [(math) (eval (cadr 'form))]
>>>      [(html) (html-template
>>>               (eval (cadr 'form)))]) ...))
>>> 
>>> (expr-iter (title "sometitle")
>>>           (math (+ 1 2))
>>>           (html (p "hello")))
>>> 
>>> 
>>> Best regards,
>>> Philipp
>>> 
>>> ____________________
>>> Racket Users list:
>>> http://lists.racket-lang.org/users
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4373 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20130108/2d5d2668/attachment.p7s>

Posted on the users mailing list.