<HTML><BODY>Thank you. This works just fine in any place, where function is expected.<BR>But the case with "case" still doesn't work<BR><BR>(case 5<BR> [((hash-dot (+ 2 3))) 1]<BR> [else 2])<BR>=> 2<BR><BR>I think, that I need to do something with the Racket reader.<BR><BR><BR>Понедельник, 29 июля 2013, 13:53 -04:00 от Vincent St-Amour <stamourv@ccs.neu.edu>:<BR>
<BLOCKQUOTE class=mailru-blockquote style="PADDING-BOTTOM: 0px; PADDING-TOP: 0px; PADDING-LEFT: 10px; MARGIN: 10px; BORDER-LEFT: #0857a6 1px solid; PADDING-RIGHT: 0px">
<DIV>
<DIV class="js-helper js-readmsg-msg">
<STYLE type=text/css></STYLE>
<DIV class=mr_read__body id=style_13751204460000000879><BASE href="https://e.mail.ru/" target=_self>
<DIV id=style_13751204460000000879_BODY>Here's a quick solution:<BR><BR> #lang racket<BR><BR> (define-syntax-rule (hash-dot e)<BR> (let-syntax ([computed-e (lambda (stx) (datum->syntax #'e e))])<BR> (computed-e)))<BR><BR> (hash-dot (+ 2 3))<BR><BR><BR>This defines a local macro that computes the value of `e' at compile<BR>time. Any binding that you use in `e' will need to be bound at syntax<BR>time (which, in #lang racket, is all of racket/base), which may mean<BR>using `(require (for-syntax X))'.<BR><BR>If you try to compute, say, a function at compile-time, you'll run into<BR>trouble, though.<BR><BR>Vincent<BR><BR><BR><BR>At Mon, 29 Jul 2013 06:25:21 +0400,<BR>Roman Klochkov wrote:<BR>> <BR>> [1 <multipart/alternative (7bit)>]<BR>> [1.1 <text/plain; utf-8 (base64)>]<BR>> Is there simple way to calculate during compilation. Something like #. in Common Lisp.<BR>> <BR>> For example how to do something like<BR>> (case ftype<BR>> ((#.(keyword->g-type 'enum)<BR>> #.(keyword->g-type 'flags))<BR>> (convert-to-foreign value (g-type->lisp type)))<BR>> (#.(keyword->g-type 'double)<BR>> (coerce value 'double-float))<BR>> (#.(keyword->g-type 'float)<BR>> (coerce value 'single-float))<BR>> ((#.(keyword->g-type 'int)<BR>> #.(keyword->g-type 'uint)<BR>> #.(keyword->g-type 'long)<BR>> #.(keyword->g-type 'ulong)<BR>> #.(keyword->g-type 'int64)<BR>> #.(keyword->g-type 'uint64)) <BR>> (round value))<BR>> (else value))<BR>> <BR>> <BR>> <BR>> where keyword->g-type is a function (-> symbol? exact-integer?).<BR>> <BR>> I don't want to place resulting numbers, because then there will be a lot of "magic numbers" corresponfing to different foreign types. <BR>> <BR>> <BR>> -- <BR>> Roman Klochkov<BR>> [1.2 <text/html; utf-8 (base64)>]<BR>> <BR>> [2 <text/plain; us-ascii (7bit)>]<BR>> ____________________<BR>> Racket Users list:<BR>> <A href="http://lists.racket-lang.org/users" target=_blank>http://lists.racket-lang.org/users</A><BR></DIV><BASE href="https://e.mail.ru/" target=_self></DIV></DIV></DIV></BLOCKQUOTE><BR><BR>-- <BR>Roman Klochkov<BR></BODY></HTML>