Re: [racket] eginner's question on elementary textual replacement...

2012-03-12 Thread Matthew Flatt
If you're interested in the compilation that happens after macro expansion, including constant-propagation and inlining, then try `raco make' and `raco decompile'. For example, if "alias.rkt" has (module alias racket (provide plusone) (define ONE 1) (define (plusone x) (+ x ONE)) (pl

Re: [racket] eginner's question on elementary textual replacement...

2012-03-11 Thread Robby Findler
Yes, that is correct. Macro expansion happens before any of the optimization steps performed by the compiler. Robby On Sun, Mar 11, 2012 at 4:06 PM, Thomas Chust wrote: > On Sun, 2012-03-11 at 22:00 +0100, Rüdiger Asche wrote: >> [...] >> So what made you think that defines within modules are in

Re: [racket] eginner's question on elementary textual replacement...

2012-03-11 Thread Thomas Chust
On Sun, 2012-03-11 at 22:00 +0100, Rüdiger Asche wrote: > [...] > So what made you think that defines within modules are inlined? Is it a doc > bug, or were you looking at something else than liberal expansion that needs > additional work? What does it take for define to translate into > define-

Re: [racket] eginner's question on elementary textual replacement...

2012-03-11 Thread Rüdiger Asche
Hello, in most cases you should probably simply use a regular definition like this: (define ONE 1) If that definition is not exported from the module you are writing it will probably be inlined anyway. This doesn't appear to be true. You probably refer to this snippet of the docs here:

Re: [racket] eginner's question on elementary textual replacement...

2012-03-09 Thread Rüdiger Asche
- Original Message - From: "Matthias Felleisen" To: "Rüdiger Asche" Cc: "Stephen Bloch" ; "users Users" Sent: Friday, March 09, 2012 5:28 PM Subject: Re: [racket] eginner's question on elementary textual replacement... On Mar 9,

Re: [racket] eginner's question on elementary textual replacement...

2012-03-09 Thread Matthias Felleisen
On Mar 9, 2012, at 11:00 AM, Rüdiger Asche wrote: > see my responses to Matthias for that) I didn't see a response. > ... so I wonder what a more natural or Schemish way there wsould be to tackle > such an issue… Here is what I had in mind: #lang racket #| you write things like this:

Re: [racket] eginner's question on elementary textual replacement...

2012-03-09 Thread Rüdiger Asche
True, there is no need for any particular way of representing the states as long as there is some way to test two things for equality. However, unless the compiler can be told to disregard the internal representation of the symbol, it won't eat up lookup time but representation space - ie if I

Re: [racket] eginner's question on elementary textual replacement...

2012-03-09 Thread Sam Tobin-Hochstadt
On Fri, Mar 9, 2012 at 5:59 AM, Thomas Chust wrote: > Anyway, if one worries about the performance cost of constants inlined > at compile time versus constants inlined by the JIT, then using a > language as high-level as Racket may be a mistake. Not really related to the rest of this discussion,

Re: [racket] eginner's question on elementary textual replacement...

2012-03-09 Thread Matthias Felleisen
Rüdiger, if you want to encode FSMs, you don't want to worry about in-lining constants. You want a macro that helps you write down the ENTIRE FSM and then compiles to small, efficient code. Think back to your Formal Languages course. A regexp is some alphabet Sigma, States, Initial States, Fina

Re: [racket] eginner's question on elementary textual replacement...

2012-03-09 Thread Thomas Chust
On Fri, 2012-03-09 at 06:06 -0500, Neil Van Dyke wrote: > [...] > I meant that all-caps was appropriate for CPP macros because of the > grievous syntactic breakage, such as unbalancing grouping token pairs, > and worse. > [...] Hello, yes, that's certainly less of an issue in a world of hygieni

Re: [racket] eginner's question on elementary textual replacement...

2012-03-09 Thread Stephen Bloch
On Mar 9, 2012, at 6:25 AM, Rüdiger Asche wrote: > (define (vendingmachine currentstate) > (let ((newstate > (case currentstate > [(VENDINGMACHINE_IDLE) > (if (CoinInserted) > VENDINGMACHINE_INSERTED_COIN > VENDINGMACHINE_IDLE >

Re: [racket] eginner's question on elementary textual replacement...

2012-03-09 Thread Rüdiger Asche
Hi there, #1: My graduate thesis (in 1988) was an implementation of Scheme. I do feel reasonably comfortable with tail recursion, continuations, closures and the "basics," even the basic notion of hygienic macros (which Eugene Kohlbecker had just finished his doctorate on when I studied S

Re: [racket] eginner's question on elementary textual replacement...

2012-03-09 Thread Neil Van Dyke
Thomas Chust wrote at 03/09/2012 05:41 AM: On Fri, 2012-03-09 at 05:16 -0500, Neil Van Dyke wrote: [...] CPP macros can cause many kinds of grievous syntactic breakage and surprising bugs, and so all-caps as a warning is a great idea; Java constants, on the other hand, are one of the safest

Re: [racket] eginner's question on elementary textual replacement...

2012-03-09 Thread Thomas Chust
On Fri, 2012-03-09 at 05:48 -0500, Neil Van Dyke wrote: > First of all, sounds like you have a substandard C compiler, and that > you must be targeting a 4-bit microcontroller. :) > [...] Hello, unfortunately, crazy proprietary microcontrollers do tend to have sub-standard compiler support ;-)

Re: [racket] eginner's question on elementary textual replacement...

2012-03-09 Thread Neil Van Dyke
First of all, sounds like you have a substandard C compiler, and that you must be targeting a 4-bit microcontroller. :) Regarding these micro-optimizations in Racket: if you are fairly new to Racket (I don't know), my suggestion is to avoid trying to optimize every word of allocation and every

Re: [racket] eginner's question on elementary textual replacement...

2012-03-09 Thread Thomas Chust
On Fri, 2012-03-09 at 05:16 -0500, Neil Van Dyke wrote: > [...] > CPP macros can cause many kinds of grievous syntactic breakage and > surprising bugs, and so all-caps as a warning is a great idea; Java > constants, on the other hand, are one of the safest constructs. > [...] Hello, although slig

Re: [racket] eginner's question on elementary textual replacement...

2012-03-09 Thread Rüdiger Asche
Thanks, Neil - of course I could always use variables - one could do the same thing in C, using const unsigned char ONE = 1; The reason why one doesn't do it in C is that it costs you useless storage, execution time overhead (the compiler can generally generate more efficient code assign

Re: [racket] eginner's question on elementary textual replacement...

2012-03-09 Thread Thomas Chust
On Fri, 2012-03-09 at 10:39 +0100, Rüdiger Asche wrote: > [...] > I need a counterpart for the C #define statement, meaning a way to > textually replace every instance of id at preprocessor time with its > defined value, as in > [...] Hello, in most cases you should probably simply use a regu

Re: [racket] eginner's question on elementary textual replacement...

2012-03-09 Thread Neil Van Dyke
Rüdiger Asche wrote at 03/09/2012 04:39 AM: (let-syntax [(ONE 1)] ((lambda (x) (+ ONE x)) 2)) won't work... so how do I do it? If you really want to do this, here are two ways: (let-syntax [(ONE (syntax-rules () ((ONE) 1)))] ((lambda (x) (+ (ONE) x)) 2)) (let-syntax [(ONE (syntax

[racket] eginner's question on elementary textual replacement...

2012-03-09 Thread Rüdiger Asche
Hi there, I need a counterpart for the C #define statement, meaning a way to textually replace every instance of id at preprocessor time with its defined value, as in #define ONE 1 unsigned int addone(unsigned int theArg) { return (theArg + ONE); } I understand that Scheme's macro sy