<HTML><BODY>It will evaluate (state 'init) and so on in runtime a lot of times.<BR><BR>Of course, I can write a case-like syntax which will process all case-values with given function.<BR><BR>Something like<BR><BR>(case+ x<BR> #:selector state<BR> ((init stage) (initialize))<BR> ((process) (function1))<BR> ((fail) (function2)))<BR><BR>#. if once written, allows avoid writing a lot of such ad-hoc syntaxes.<BR><BR>And it can be used to make version- and platform-independent code like #ifdef in C<BR><BR>Понедельник, 29 июля 2013, 21:03 -04:00 от Matthias Felleisen <matthias@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_13751461710000000259><BASE href="https://e.mail.ru/" target=_self>
<DIV id=style_13751461710000000259_BODY>
<DIV><BR></DIV>
<DIV>Try evcase </DIV><BR>
<DIV>
<DIV>On Jul 29, 2013, at 8:48 PM, Roman Klochkov wrote:</DIV><BR>
<BLOCKQUOTE type="cite">
<DIV><BR>
<DIV>
<DIV id=style_13751452590000000043>
<DIV id=style_13751452590000000043_BODY>#. calcuclates its argument and place it in the program code.<BR>Now I have to write something like <BR><BR>(case state-number<BR> ((0 1) ; state in init, stage1<BR> (initialize))<BR> ((2) ; state = process<BR> (function1)<BR> ((3) ; state = abort<BR> (function2)))<BR><BR>I want to have<BR><BR>(define (state x)<BR> (let rec ([states '(init stage1 process fail)]<BR> [pos 0])<BR> (cond<BR> [(null? states) #f]<BR> [(eq? (car states) x) pos]<BR> [else (rec (cdr states) (add1 pos))])))<BR><BR>(case state-number<BR> ((#.(state 'init) #.(state 'stage1))<BR> (initialize))<BR> ((#.(state 'process))<BR> (function1)<BR> ((#.(state 'fail))<BR> (function2)))<BR><BR>So the code becomes self-documenting. Like using enum values in C or Pascal.<BR><BR>Понедельник, 29 июля 2013, 13:32 -04:00 от Asumu Takikawa <<A href="https://e.mail.ru/messages/inbox/sentmsg?mailto=mailto%3aasumu@ccs.neu.edu" target=_blank>asumu@ccs.neu.edu</A>>:<BR>
<BLOCKQUOTE style="PADDING-BOTTOM: 0px; PADDING-TOP: 0px; PADDING-LEFT: 10px; MARGIN: 10px; BORDER-LEFT: #0857a6 1px solid; PADDING-RIGHT: 0px">
<DIV>
<DIV>
<DIV id=style_13751191470000000143>
<DIV id=style_13751191470000000143_BODY>On 2013-07-29 06:25:21 +0400, Roman Klochkov wrote:<BR>> Is there simple way to calculate during compilation. Something like #.<BR>> in Common Lisp.<BR><BR>Can you tell us what #. means in Common Lisp?<BR><BR>I am guessing that you want to do something like the following:<BR><BR> #lang racket<BR> (require (for-syntax syntax/parse))<BR><BR> ;; functions to compute costly constants<BR> ;; at compile-time<BR> (begin-for-syntax<BR> (define (compute-x) ...)<BR> (define (compute-y) ...)<BR> (define (compute-z) ...))<BR><BR> ;; macro that defines x, y, z assuming<BR> ;; suitable definitions of compute-x, etc.<BR> (define-syntax (define-constants stx)<BR> (syntax-parse stx<BR> [(_ x:id y:id z:id)<BR> #`(begin (define x #,(compute-x))<BR> (define y #,(compute-y))<BR> (define z #,(compute-z)))]))<BR><BR> (define-constants my-x my-y my-z)<BR><BR>This will work if the `compute-` functions produce flat data that can be<BR>embedded in syntax, like numbers.<BR><BR>Cheers,<BR>Asumu<BR></DIV></DIV></DIV></DIV></BLOCKQUOTE><BR><BR>-- <BR>Roman Klochkov<BR></DIV></DIV></DIV><BR>
<HR>
<BR>-- <BR>Roman Klochkov<BR></DIV>____________________<BR> Racket Users list:<BR> <A href="http://lists.racket-lang.org/users" target=_blank>http://lists.racket-lang.org/users</A><BR></BLOCKQUOTE></DIV><BR></DIV><BASE href="https://e.mail.ru/" target=_self></DIV></DIV></DIV></BLOCKQUOTE><BR><BR>-- <BR>Roman Klochkov<BR></BODY></HTML>