<html><head><base href="https://e.mail.ru/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div>You will need to combine EVCASE with Vincent's hash-dot. I can't see why this should evaluate (init state) more than once. </div><div><br></div><br><div><div>On Jul 29, 2013, at 9:16 PM, Roman Klochkov wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">
<div>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 <<a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>>:<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></div>
</blockquote></div><br></body></html>