Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

at-expand-time
I came up with a handy macro and I thought I'd see what your comments
on it were.  It's a Scheme replacement for Lisp's eval-when, called
"at-expand-time".  Although Scheme doesn't have an explicit compile
stage, it usually corresponds with macroexpand time.  Anyway, this
little syntax-case macro does compile-time evaluation.  I've tested it
with Chicken, and wondered what you all thought of it.

I'm posting from Google, so I apologize if this comes through jumbled.

;;Define our macro
(define-syntax at-compile-time
;;x is the syntax object to be transformed
(lambda (x)
(syntax-case x ()
(
;;Pattern just like a syntax-rules pattern
(at-compile-time expression)

;;with-syntax allows us to build syntax objects
;;dynamically
(with-syntax
(
;this is the syntax object we are building
(expression-value
;after computing expression, transform it into a syntax
object
(datum->syntax-object
;syntax domain
(syntax at-compile-time)
;quote the value so that its a literal value
(list 'quote
;compute the value to transform
(eval
;;convert the expression from the syntax
;;representation to a list representation
(syntax-object->datum (syntax expression)))))))
;;Just return the generated value as the result
(syntax expression-value))))))

(define calculated-at-compile-time (at-compile-time (sqrt 5)))

Anyway, I'm still pretty new to macros, so let me know what you think!


Report this thread to moderator Post Follow-up to this message
Old Post
johnnyb@eskimo.com
05-31-05 09:01 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Scheme archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:33 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.