<div dir="ltr">Hmm, perhaps this would be easier to define the problem if I were to share the code for where this has to go. <div><br></div><div>Currently, my struct system looks like this: <a href="https://github.com/jarcane/heresy/blob/master/lib/things.rkt">https://github.com/jarcane/heresy/blob/master/lib/things.rkt</a></div><div><br></div><div>Now, as it stands this works quite well as an opaque data structure, but they can in theory be extended into a full blown object system if we store lambdas in one of our Things. This is at the moment kind of a useless gesture though, it's not clear they can self-reflect from within the same scope.</div><div><br></div><div>But! If we can wrap a second let around the first there, that expands our alist into defining each field as an individual local variable, then any function called with our regular syntax would be able to refer to the variables of the parent function. I've tested this in toy form, and the scoping does appear to support it.</div><div><br></div><div>But we need the expanding let to do it, and so far I've failed to come up with a way, and the solutions thus far require manual operations, not something general. The last two posts have the same 'out of context' problem if they attempt to operate on the argument of the Thing function, because it's not an explicit value being declared manually, but using an existing variable in the function that we need. </div><div><br></div><div>Perhaps Things need to start from scratch as a full macro, but the problem I ran into was the recursive call used for returning a Thing copy just creates an infinite loop if done as a macro. It's fine as a function. </div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec 11, 2014 at 10:10 PM, Alexander D. Knauth <span dir="ltr"><<a href="mailto:alexander@knauth.org" target="_blank">alexander@knauth.org</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Or you don’t even need a syntax-parameter:</div><div><span class=""><div>#lang racket</div><div>(require (for-syntax syntax/parse))</div></span><span class=""><div>(define-syntax letexpand</div><div> (syntax-parser</div><div>   [(_ alst body ...)</div></span><div>    (with-syntax ([alst (syntax-local-introduce #`#,(syntax-local-value #'alst))])</div><span class=""><div>      #'(let alst body ...))]))</div><div>(define (foo)</div></span><div>  (define-syntax dave '((is 5) (fat 6)))</div><span class=""><div>  (letexpand dave is fat))</div><div>(foo)</div></span></div><div><div class="h5"><br><div><div>On Dec 11, 2014, at 6:52 AM, Roman Klochkov <<a href="mailto:kalimehtar@mail.ru" target="_blank">kalimehtar@mail.ru</a>> wrote:</div><br><blockquote type="cite"><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><p>#lang racket<br>(require (for-syntax syntax/parse) racket/stxparam)</p><p>(define-syntax letexpand<br>  (syntax-parser<br>  [(_ alst body ...)<br>    (with-syntax ([alst (syntax-local-introduce #`#,(syntax-parameter-value #'alst))])<br>        #'(let alst body ...))]))</p><p>(define (foo)<br>    (define-syntax-parameter dave '((is 4) (fat 6)))<br>    (letexpand dave is fat))</p><p>(foo)</p><br><br><br>Tue, 9 Dec 2014 06:33:14 +0200 от J Arcane <<a href="mailto:jarcane@gmail.com" target="_blank">jarcane@gmail.com</a>>:<br><blockquote style="border-left-width:1px;border-left-style:solid;border-left-color:rgb(8,87,166);margin:10px;padding:0px 0px 0px 10px"><div><div><div><div dir="ltr">Hmm. That does appear to work at a global level, but then when you attempt to use it inside of a function it returns "identifier used out of context". Trying to define-for-syntax in a local context also causes problems; "begin-for-syntax: not in a definition context in: (begin-for-syntax (define-values (z) lst))"</div><div><br><div>On Mon, Dec 8, 2014 at 10:17 PM, Alexander D. Knauth<span> </span><span dir="ltr"><<a>alexander@knauth.org</a>></span><span> </span>wrote:<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Would something like this work for what you want?<br><br>#lang racket<br>(require (for-syntax syntax/parse))<br>(define-for-syntax dave '((is 5) (fat 6)))<br>(define-syntax letexpand<br>  (syntax-parser<br>    [(_ alst body ...)<br>     (with-syntax ([alst (syntax-local-introduce #`#,(eval-syntax #'alst))])<br>       #'(let alst body ...))]))<br>(letexpand dave is fat)<br><div><br>On Dec 8, 2014, at 2:46 AM, J Arcane <<a>jarcane@gmail.com</a>> wrote:<br><br>> I've been experimenting with a new feature for Heresy, and I find myself in need of a macro that can insert the contents of an a-list into a let syntax to serve as its definitions. I am utterly failing to accomplish this. It seems like it should be simple enough to splice a variable's contents into the syntax, and in a sense it is, but not if I want it to actually then evaluate.<br>><br>> For example, I can do this:<br>><br>> (define dave '((is 5) (fat 6)))<br>><br>> (define-syntax letexpand<br>>   (syntax-rules ()<br>>     [(_ alst body ...)<br>>      #`(let #,alst body ...)]))<br>><br>> (letexpand dave is fat)<br>><br>> Which returns a syntax object which looks like what I want:<br>><br>> #<syntax:...:8:7 (let ((is 5) (fat 6)) is fat)><br>><br>> But doesn't actually the evaluate that object. But doing that with merely (let alst body ...) creates an error because rather than splicing alst's contents itself, it merely inserts the variable name given, and then fails because let doesn't recognize it. It will work with a handwritten unquoted alist in that space, but this is largely useless because of course that's what let already basically does anyway.<br>><br>> Am I starting in the wrong place here, and if not, how do I turn that syntax object into something that actually evaluates?<br></div>> ____________________<br>>  Racket Users list:<br>> <span> </span><a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br><br></blockquote></div><br></div></div><div>____________________<br>  Racket Users list:<br>  <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br><br></div></div></div></blockquote><br><br>--<span> </span><br>Roman Klochkov</div></blockquote></div><br></div></div></div></blockquote></div></div>