<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>Try evcase </div><br><div><div>On Jul 29, 2013, at 8:48 PM, Roman Klochkov wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">
<div><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 <<a href="mailto:asumu@ccs.neu.edu">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><base href="https://e.mail.ru/" target="_self"></div></div><br>
<hr>
<br>-- <br>Roman Klochkov<br></div>
____________________<br> Racket Users list:<br> <a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></blockquote></div><br></body></html>