[racket-users] Task ,drracket problems solution

2019-01-27 Thread ristovska . karolina77
How can I find the largest-divisor on one integer 
ex : (largest-divisor  256) -> 128
   (largest-divisor  6) -> 3

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Problem controlling macro expansion

2019-01-27 Thread Jonathan Simpson
Thanks. I think I have a better approach now, thanks to your earlier 
comments. There are still some issues to work out, but I think I'm on the 
right track!

-- Jonathan

On Sunday, January 27, 2019 at 5:18:04 PM UTC-5, Matthias Felleisen wrote:
>
>
> See docs for local-expand. 
>
>
> On Jan 27, 2019, at 5:15 PM, Jonathan Simpson  > wrote:
>
> The code contained within lines-to-syntax-tree will run tests on an input 
> stream. My original plan was to have a function like run-query that would 
> execute the tests. So I'd need to quote the tests because they'd be 
> executed in an order defined by run-query.
>
> I will look into making run-query a macro that expands into the code that 
> runs the tests. That may be easier in the long run anyway. Plus I'd like to 
> avoid eval in my runtime code.
>
> I am curious if there is an easy way to expand lines-to-syntax-tree and 
> then quote it though. I'm having a hard time making the macro system do 
> what I want. I usually know what needs to be done, but quickly run into 
> things that I don't understand.
>
> Thanks,
> Jonathan
>
> On Sunday, January 27, 2019 at 4:08:54 PM UTC-5, Matthias Felleisen wrote:
>>
>>
>> Why is run-query not a macro and if it were, why would you quote 
>> lines-to-syntax-tree? 
>>
>>
>> On Jan 27, 2019, at 4:06 PM, Jonathan Simpson  wrote:
>>
>> I'm having macro troubles with a DSL I'm writing. I have a macro that 
>> looks something like this:
>>
>> (define-syntax (query stx)
>>   (let ([lines (cdr (syntax->datum stx))])
>> (define lines-syntax-tree (parse-to-tree lines))
>> (datum->syntax stx lines-syntax-tree)))
>>
>> So something like 
>>
>> (query ...linear series of s-expressions containing non-nested code...)
>>
>> is transformed into (...hierarchical code in tree form...).
>>
>> But what I really want is
>>
>> (run-query '(...code in tree form...))
>>
>> The code that I'd like quoted and passed to run-query has a number of 
>> macros I wrote that also need expanding. My problem is that all of my 
>> attempts to write a macro that results in run-query being passed a list of 
>> code to execute blocks the expansion of the passed code. Basically, I want 
>> to expand 'lines-syntax-tree' before I quote it and generate an expansion 
>> including run-query.
>>
>> For instance, this obviously doesn't work:
>>
>> (define-syntax (query stx)
>>   (let ([lines (cdr (syntax->datum stx))])
>> (define lines-syntax-tree (parse-to-tree lines))
>> (define q (list 'run-query (quote lines-syntax-tree)))
>> (datum->syntax stx q)))
>>
>> I'm sure I'm missing something silly, but I'd appreciate any help. I 
>> should probably read 
>> https://docs.racket-lang.org/reference/syntax-model.html, but it is 
>> going to take me some time to grok that.
>>
>> Thanks,
>> Jonathan
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users...@googlegroups.com .
> For more options, visit https://groups.google.com/d/optout.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Problem controlling macro expansion

2019-01-27 Thread Jonathan Simpson
I gave this a try and it appears to break my parse-to-tree function. Thanks 
for the warning though. Once I get this working it will be worth going back 
to this.

Thanks,
Jonathan

On Sunday, January 27, 2019 at 5:03:17 PM UTC-5, Jens Axel Søgaard wrote:
>
>
>
> Den søn. 27. jan. 2019 kl. 22.06 skrev Jonathan Simpson  >:
>
>> I'm having macro troubles with a DSL I'm writing. I have a macro that 
>> looks something like this:
>>
>> (define-syntax (query stx)
>>   (let ([lines (cdr (syntax->datum stx))])
>> (define lines-syntax-tree (parse-to-tree lines))
>> (datum->syntax stx lines-syntax-tree)))
>>
>
> You are throwing away all location informations in the call 
> `(syntax->datum stx)`.
> Consider using `(syntax->list stx)` instead.
>
> /Jens Axel
>
>  
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Problem controlling macro expansion

2019-01-27 Thread Matthias Felleisen

See docs for local-expand. 


> On Jan 27, 2019, at 5:15 PM, Jonathan Simpson  wrote:
> 
> The code contained within lines-to-syntax-tree will run tests on an input 
> stream. My original plan was to have a function like run-query that would 
> execute the tests. So I'd need to quote the tests because they'd be executed 
> in an order defined by run-query.
> 
> I will look into making run-query a macro that expands into the code that 
> runs the tests. That may be easier in the long run anyway. Plus I'd like to 
> avoid eval in my runtime code.
> 
> I am curious if there is an easy way to expand lines-to-syntax-tree and then 
> quote it though. I'm having a hard time making the macro system do what I 
> want. I usually know what needs to be done, but quickly run into things that 
> I don't understand.
> 
> Thanks,
> Jonathan
> 
> On Sunday, January 27, 2019 at 4:08:54 PM UTC-5, Matthias Felleisen wrote:
> 
> Why is run-query not a macro and if it were, why would you quote 
> lines-to-syntax-tree? 
> 
> 
>> On Jan 27, 2019, at 4:06 PM, Jonathan Simpson gmail.com 
>> > wrote:
>> 
>> I'm having macro troubles with a DSL I'm writing. I have a macro that looks 
>> something like this:
>> 
>> (define-syntax (query stx)
>>   (let ([lines (cdr (syntax->datum stx))])
>> (define lines-syntax-tree (parse-to-tree lines))
>> (datum->syntax stx lines-syntax-tree)))
>> 
>> So something like 
>> 
>> (query ...linear series of s-expressions containing non-nested code...)
>> 
>> is transformed into (...hierarchical code in tree form...).
>> 
>> But what I really want is
>> 
>> (run-query '(...code in tree form...))
>> 
>> The code that I'd like quoted and passed to run-query has a number of macros 
>> I wrote that also need expanding. My problem is that all of my attempts to 
>> write a macro that results in run-query being passed a list of code to 
>> execute blocks the expansion of the passed code. Basically, I want to expand 
>> 'lines-syntax-tree' before I quote it and generate an expansion including 
>> run-query.
>> 
>> For instance, this obviously doesn't work:
>> 
>> (define-syntax (query stx)
>>   (let ([lines (cdr (syntax->datum stx))])
>> (define lines-syntax-tree (parse-to-tree lines))
>> (define q (list 'run-query (quote lines-syntax-tree)))
>> (datum->syntax stx q)))
>> 
>> I'm sure I'm missing something silly, but I'd appreciate any help. I should 
>> probably read https://docs.racket-lang.org/reference/syntax-model.html 
>> , but it is going 
>> to take me some time to grok that.
>> 
>> Thanks,
>> Jonathan
>> 
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users...@ <>googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout 
>> .
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com 
> .
> For more options, visit https://groups.google.com/d/optout 
> .

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Problem controlling macro expansion

2019-01-27 Thread Jonathan Simpson
The code contained within lines-to-syntax-tree will run tests on an input 
stream. My original plan was to have a function like run-query that would 
execute the tests. So I'd need to quote the tests because they'd be 
executed in an order defined by run-query.

I will look into making run-query a macro that expands into the code that 
runs the tests. That may be easier in the long run anyway. Plus I'd like to 
avoid eval in my runtime code.

I am curious if there is an easy way to expand lines-to-syntax-tree and 
then quote it though. I'm having a hard time making the macro system do 
what I want. I usually know what needs to be done, but quickly run into 
things that I don't understand.

Thanks,
Jonathan

On Sunday, January 27, 2019 at 4:08:54 PM UTC-5, Matthias Felleisen wrote:
>
>
> Why is run-query not a macro and if it were, why would you quote 
> lines-to-syntax-tree? 
>
>
> On Jan 27, 2019, at 4:06 PM, Jonathan Simpson  > wrote:
>
> I'm having macro troubles with a DSL I'm writing. I have a macro that 
> looks something like this:
>
> (define-syntax (query stx)
>   (let ([lines (cdr (syntax->datum stx))])
> (define lines-syntax-tree (parse-to-tree lines))
> (datum->syntax stx lines-syntax-tree)))
>
> So something like 
>
> (query ...linear series of s-expressions containing non-nested code...)
>
> is transformed into (...hierarchical code in tree form...).
>
> But what I really want is
>
> (run-query '(...code in tree form...))
>
> The code that I'd like quoted and passed to run-query has a number of 
> macros I wrote that also need expanding. My problem is that all of my 
> attempts to write a macro that results in run-query being passed a list of 
> code to execute blocks the expansion of the passed code. Basically, I want 
> to expand 'lines-syntax-tree' before I quote it and generate an expansion 
> including run-query.
>
> For instance, this obviously doesn't work:
>
> (define-syntax (query stx)
>   (let ([lines (cdr (syntax->datum stx))])
> (define lines-syntax-tree (parse-to-tree lines))
> (define q (list 'run-query (quote lines-syntax-tree)))
> (datum->syntax stx q)))
>
> I'm sure I'm missing something silly, but I'd appreciate any help. I 
> should probably read 
> https://docs.racket-lang.org/reference/syntax-model.html, but it is going 
> to take me some time to grok that.
>
> Thanks,
> Jonathan
>
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users...@googlegroups.com .
> For more options, visit https://groups.google.com/d/optout.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Problem controlling macro expansion

2019-01-27 Thread Jens Axel Søgaard
Den søn. 27. jan. 2019 kl. 22.06 skrev Jonathan Simpson :

> I'm having macro troubles with a DSL I'm writing. I have a macro that
> looks something like this:
>
> (define-syntax (query stx)
>   (let ([lines (cdr (syntax->datum stx))])
> (define lines-syntax-tree (parse-to-tree lines))
> (datum->syntax stx lines-syntax-tree)))
>

You are throwing away all location informations in the call `(syntax->datum
stx)`.
Consider using `(syntax->list stx)` instead.

/Jens Axel

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Problem controlling macro expansion

2019-01-27 Thread Matthias Felleisen

Why is run-query not a macro and if it were, why would you quote 
lines-to-syntax-tree? 


> On Jan 27, 2019, at 4:06 PM, Jonathan Simpson  wrote:
> 
> I'm having macro troubles with a DSL I'm writing. I have a macro that looks 
> something like this:
> 
> (define-syntax (query stx)
>   (let ([lines (cdr (syntax->datum stx))])
> (define lines-syntax-tree (parse-to-tree lines))
> (datum->syntax stx lines-syntax-tree)))
> 
> So something like 
> 
> (query ...linear series of s-expressions containing non-nested code...)
> 
> is transformed into (...hierarchical code in tree form...).
> 
> But what I really want is
> 
> (run-query '(...code in tree form...))
> 
> The code that I'd like quoted and passed to run-query has a number of macros 
> I wrote that also need expanding. My problem is that all of my attempts to 
> write a macro that results in run-query being passed a list of code to 
> execute blocks the expansion of the passed code. Basically, I want to expand 
> 'lines-syntax-tree' before I quote it and generate an expansion including 
> run-query.
> 
> For instance, this obviously doesn't work:
> 
> (define-syntax (query stx)
>   (let ([lines (cdr (syntax->datum stx))])
> (define lines-syntax-tree (parse-to-tree lines))
> (define q (list 'run-query (quote lines-syntax-tree)))
> (datum->syntax stx q)))
> 
> I'm sure I'm missing something silly, but I'd appreciate any help. I should 
> probably read https://docs.racket-lang.org/reference/syntax-model.html, but 
> it is going to take me some time to grok that.
> 
> Thanks,
> Jonathan
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com 
> .
> For more options, visit https://groups.google.com/d/optout 
> .

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Problem controlling macro expansion

2019-01-27 Thread Jonathan Simpson
I'm having macro troubles with a DSL I'm writing. I have a macro that looks 
something like this:

(define-syntax (query stx)
  (let ([lines (cdr (syntax->datum stx))])
(define lines-syntax-tree (parse-to-tree lines))
(datum->syntax stx lines-syntax-tree)))

So something like 

(query ...linear series of s-expressions containing non-nested code...)

is transformed into (...hierarchical code in tree form...).

But what I really want is

(run-query '(...code in tree form...))

The code that I'd like quoted and passed to run-query has a number of 
macros I wrote that also need expanding. My problem is that all of my 
attempts to write a macro that results in run-query being passed a list of 
code to execute blocks the expansion of the passed code. Basically, I want 
to expand 'lines-syntax-tree' before I quote it and generate an expansion 
including run-query.

For instance, this obviously doesn't work:

(define-syntax (query stx)
  (let ([lines (cdr (syntax->datum stx))])
(define lines-syntax-tree (parse-to-tree lines))
(define q (list 'run-query (quote lines-syntax-tree)))
(datum->syntax stx q)))

I'm sure I'm missing something silly, but I'd appreciate any help. I should 
probably read https://docs.racket-lang.org/reference/syntax-model.html, but 
it is going to take me some time to grok that.

Thanks,
Jonathan

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.