<HTML><BODY><BR>
<DIV class="js-helper js-readmsg-msg">
<STYLE type=text/css></STYLE>
<DIV class=mr_read__body id=style_13751452590000000043><BASE href="https://e.mail.ru/" target=_self>
<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 <asumu@ccs.neu.edu>:<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><BASE href="https://e.mail.ru/" target=_self></DIV></DIV><BR>
<HR>
<BR>-- <BR>Roman Klochkov<BR></BODY></HTML>