Re: [racket-users] Question about structuring recursive code

2015-09-23 Thread Alexis King
> Ok. Yeah, if- branches aren't allowed to have definitions, or even sequences 
> of operations. You can get around this with begin

Er, no you can’t... `begin` doesn’t create an internal definition context (or 
even a new scope). You can use an empty `let` instead:

(define (f x)
  (if (even? x)
  (/ x 2)
  (let ()
(define a (* x 2))
(define b (* x 3))
(f (+ a b)

Or you can use `block` from racket/block.

-- 
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] Re: Problems with building of Racket compiler with multiple threads

2015-09-23 Thread Juan Francisco Cantero Hurtado
What is the OS and the compiler? If you're using some unix-like OS, the 
output of "ulimit -a" would be useful.


On 09/22/2015 10:34 AM, Дмитрий Кашин wrote:

Dear all,

I wanna notice that it was originally sent into us...@racket-lang.org mailing 
list, but it was rejected by list's moderator because list had been moved to 
Google Groups. So I resend it via Gmail.

I did not understand how to send and to get letters here with my mail client, 
so I have some problems with communication here. I'd be glad if somebody 
explains me how to do it: I'm really newbie with Google Groups.

-

Hello everybody.

Our company produces DPL systems using Racket Scheme language. Sometimes (but 
very rare) we make some contributions to the Racket standard collections, and 
we have a big problem: the rebuild process of Racket takes about 4 hours, and 
it harms our continuous integration process. Espesially it harms us when we 
want to set up a new build stand. I wanted to decrease this time using multiple 
threads because I heard that Raco can work with them.

While building the compiler itself I used "make -jN". I've been also trying to set 
PLT_SETUP_OPTIONS to "-j N" where N is a number of threads.

But I've found that the build in this way can produce some inconsistent result. 
Builds with 8 threads has crashed as bad as with 7 ones. With 6 threads the 
build has finished with success in 20 minutes for 3 times, but then 3 times 
failed with different SIGSEGV errors.

Here are some of them:
1. SIGSEGV MAPERR si_code 1 fault on addr 0x7fd774b54018
2. SIGSEGV SI_KERNEL SI_ERRNO 0 fault on addr (nil)

They could happen at random time at compilation of random collection. Address 
could be nil or some different. The second error was seen by me more often than 
the first one.

I suppose that it's the problem of GC because it uses SIGSEGV for some 
purposes. Maybe I should disable GC? But is it possible and how?
I need a recommendation how to solve this problem. Does somebody build Racket 
with multiple threads? Is there a correct way to do it? How could I achieve a 
consistent build?

UPD:
I've set PLTDISABLEGC="1" trying to disable GC. And I've got the same: "SIGSEGV 
MAPERR si_code 1 fault on addr 0x8".
So I think it could be not a garbage collector's problem.

BTW, I want to understand how raco does parallel building process into threads. 
I know that racket does not have native threads, but has only green ones. But 
in htop I saw numerous threads (I suppose it was threads because they shared 
the save virtual memory). How could it be? Do raco use native threads because 
it's written not in Racket but in C/C++?

UPD#2:
I returned to a consistent building of racket with 1 thread. I don't see a way 
how to have guarantees that the build is fine with such a strange raco's 
behavior. Need a discussion.




--
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] Ambiguous binding error, and trying to add generic-interface inheritance

2015-09-23 Thread Alexander D. Knauth
I'm trying to add inheritance to generic interfaces:
https://github.com/AlexKnauth/racket/tree/gen-extends 


But it's in a weird state where it's passing some of the time, (seemingly 
depending on how exactly I fiddle with it, compile it, restart DrRacket, and/or 
other things), but the other times it's giving me ambiguous binding errors like 
this:

https://travis-ci.org/AlexKnauth/racket/jobs/81884173#L1461 


pkgs/racket-test/tests/generic/extend.rkt:6:3: get: identifier's binding is 
ambiguous
  context...:
   #(894142 module) #(894143 module extend 0) #(895177 macro) #(895618 local)
   #(895650 intdef) #(895651 local) #(895652 intdef) #(895655 local)
   #(895656 intdef) #(895661 local) #(895663 intdef) #(895664 local)
   #(895665 intdef) #(895666 local) #(895667 intdef) #(895671 local)
   #(895673 intdef) #(895674 local) #(895675 intdef)
  matching binding...:
   local get128618
   #(894142 module) #(894143 module extend 0) #(895618 local) #(895650 intdef)
   #(895651 local) #(895652 intdef) #(895655 local) #(895656 intdef) #(895661 
local)
   #(895663 intdef) #(895664 local) #(895665 intdef) #(895666 local)
   #(895667 intdef) #(895671 local) #(895673 intdef) #(895674 local)
   #(895675 intdef)
  matching binding...:
   local get128614
   #(894142 module) #(894143 module extend 0) #(895177 macro) #(895618 local)
   #(895650 intdef) #(895651 local) #(895652 intdef) #(895655 local)
   #(895656 intdef) #(895661 local) #(895663 intdef) #(895664 local)
   #(895665 intdef) #(895666 local)
  matching binding...:
   #f
   #(894142 module) #(894143 module extend 0)
  in: get
  compilation context...:
   
/Users/travis/build/AlexKnauth/racket/pkgs/racket-test/tests/generic/extend.rkt
  context...:
   
/Users/travis/build/AlexKnauth/racket/racket/collects/racket/private/generic-methods.rkt:161:2

I'm also getting errors from data/order.rkt, but that's a separate problem, and 
an easy one to fix. (I already did on my computer, but Travis is getting 
data/order from the package, not from my computer.)

Do you have any idea what's going on, or how to do this right?

Thanks!
Alex Knauth

-- 
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] Question about structuring recursive code

2015-09-23 Thread Kaushik Ghose
Very neat! Thank you! Best -Kaushik

On Wed, Sep 23, 2015 at 7:46 PM, Benjamin Greenman <
benjaminlgreen...@gmail.com> wrote:

>
> On Wed, Sep 23, 2015 at 7:38 PM, Kaushik Ghose 
> wrote:
>
>> I haven't gotten to cond yet.
>
>
> Ok. Yeah, if- branches aren't allowed to have definitions, or even
> sequences of operations. You can get around this with begin:
>
> (define (f x)
>   (if (even? x)
>   (/ x 2)
>   (begin
> (define a (* x 2))
> (define b (* x 3))
> (f (+ a b)
>
> --
>

-- 
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] Question about structuring recursive code

2015-09-23 Thread Benjamin Greenman
On Wed, Sep 23, 2015 at 7:38 PM, Kaushik Ghose 
wrote:

> I haven't gotten to cond yet.


Ok. Yeah, if- branches aren't allowed to have definitions, or even
sequences of operations. You can get around this with begin:

(define (f x)
  (if (even? x)
  (/ x 2)
  (begin
(define a (* x 2))
(define b (* x 3))
(f (+ a b)

--

-- 
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] Question about structuring recursive code

2015-09-23 Thread Kaushik Ghose
PS

On Wed, Sep 23, 2015 at 7:38 PM, Kaushik Ghose 
wrote:

> Hi!
>
> On Wed, Sep 23, 2015 at 7:33 PM, Benjamin Greenman <
> benjaminlgreen...@gmail.com> wrote:
>
>> Could you post the "ugly" code? I'm curious because things like this
>> compile fine:
>>
>> The ugly code looks like:

(define (f x)
  (if (even? x)
  (/ x 2)
  ((let* ([a (* x 2)]
  [b (* x 3)])
   (f (+ a b))

-- 
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] Question about structuring recursive code

2015-09-23 Thread Kaushik Ghose
Hi!

On Wed, Sep 23, 2015 at 7:33 PM, Benjamin Greenman <
benjaminlgreen...@gmail.com> wrote:

> Could you post the "ugly" code? I'm curious because things like this
> compile fine:
>
> (define (f-recur x y)
>  (cond ((< x 1)
> 10)
>   (else
>(define z 3)
>(f-recur x y
>
> I'm doing:

(define (f x)
  (if (even? x)
  (/ x 2)
  ((define a (* x 2))
   (define b (* x 3))
   (f (+ a b)

I haven't gotten to cond yet.

-- 
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] Question about structuring recursive code

2015-09-23 Thread Benjamin Greenman
Could you post the "ugly" code? I'm curious because things like this
compile fine:

(define (f-recur x y)
 (cond ((< x 1)
10)
  (else
   (define z 3)
   (f-recur x y

On Wed, Sep 23, 2015 at 7:25 PM, Kaushik Ghose 
wrote:

>
> On Wed, Sep 23, 2015 at 12:26 PM, Pierpaolo Bernardi 
>> wrote:
>>
>>> On Wed, Sep 23, 2015 at 6:18 PM, Kaushik Ghose 
>>> wrote:
>>>
>>> > Can I have any statements in this block that I could have in a (define
>>> ...)
>>> > block? Can I have (defines ) for example?
>>>
>>> Yes, and yes  :)
>>>
>>
>> Hmm. I get a "define: not allowed in an expression context" when I try to
> do that. I did manage to use nested let* and let-values to achieve my goal,
> though it looks pretty ugly.
>
> --
> 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] Question about structuring recursive code

2015-09-23 Thread Kaushik Ghose
> On Wed, Sep 23, 2015 at 12:26 PM, Pierpaolo Bernardi 
> wrote:
>
>> On Wed, Sep 23, 2015 at 6:18 PM, Kaushik Ghose 
>> wrote:
>>
>> > Can I have any statements in this block that I could have in a (define
>> ...)
>> > block? Can I have (defines ) for example?
>>
>> Yes, and yes  :)
>>
>
> Hmm. I get a "define: not allowed in an expression context" when I try to
do that. I did manage to use nested let* and let-values to achieve my goal,
though it looks pretty ugly.

-- 
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] Generating preorders

2015-09-23 Thread Jerzy Karczmarczuk

A general remark...

Josh Grams solves the problem of ->

Erich Rast wrote:

>Someone on stackoverflow gave me a working implementation in Python 3
>
>https://stackoverflow.com/questions/3269/
>
>but it uses advanced features and I have no clue how to translate this
>to Racket.
Josh constructs the list of ALL combinations and all total preorders. 
Erich apparently tried the same, so it is OK, but the solution in Python 
with generators is more economic, incremental, "non-deterministic". This 
somehow didn't appeal to Erich, who calls it an "advanced" feature of 
Python...


But we have generators in Racket as well!!
Use (require racket/generator)
and you have your (generator ...);  (yield...) etc. The syntax of 
generators in Racket is a bit clumsy, but the Python solution can be 
mapped to Racket as it is.


Eli gives a small tutorial here:

http://stackoverflow.com/questions/25291125/racket-how-to-define-a-recursive-generator-like-python


Jerzy Karczmarczuk

--
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] Redex, traces and Graphviz

2015-09-23 Thread Robby Findler
Yes, but only in a fairly complex way. Your rendering function would
have to call out to graphviz, get the results back as a png, use
read-bitmap to get the png back into Racket, create an image snip and
then insert that into the editor, using the more complex version of
the `pp` argument.

Here's an example.

Robby

#lang racket/gui

(define (dot-render t)
  (define-values (dot-input-in dot-input-out) (make-pipe))
  (define-values (dot-output-in dot-output-out) (make-pipe))
  (thread
   (λ ()
 (define n 0)
 (define (next) (set! n (+ n 1)) (format "x~a" n))
 (fprintf dot-input-out "digraph {\n")
 (let loop ([t t])
(define me (next))
(match t
  [`(,e1 ,e2 ,e3)
   (fprintf dot-input-out "  ~a [label=\"\" width=.2 height=.2]\n" me)
   (fprintf dot-input-out "  ~a -> ~a\n" me (loop e1))
   (fprintf dot-input-out "  ~a -> ~a\n" me (loop e2))
   (fprintf dot-input-out "  ~a -> ~a\n" me (loop e3))
   me]
  [_
   (fprintf dot-input-out "  ~a [shape=point]\n" me)
   me]))
  (fprintf dot-input-out "}\n")
 (close-output-port dot-input-out)))
  (thread (λ ()
(parameterize ([current-output-port dot-output-out]
   [current-input-port dot-input-in])
  (system "/usr/local/bin/dot -T png"))
(close-output-port dot-output-out)))
  (read-bitmap dot-output-in))

(require redex)
(define-language L
  (e ::= (e e e) ⊥))
(define red
  (reduction-relation
   L
   (--> e (e ⊥ ⊥))
   (--> e (⊥ e ⊥))
   (--> e (⊥ ⊥ e

(traces red
(term ⊥)
#:pp
(λ (t port n txt)
  (send txt insert (make-object image-snip% (dot-render t)



On Wed, Sep 23, 2015 at 12:05 PM, Anton Podkopaev  wrote:
> Hello!
>
> I'm working on an operational semantics using PLT Redex. I use `traces` a lot 
> to debug my semantics. To represent states in a nice way I'm using a pretty 
> printer, but I want more -- I want to use Graphviz. Is it somehow possible to 
> call Graphviz from my pretty printer, and incorporate a result of rendering 
> into a pretty-printed text?
>
> BR,
> Anton Podkopaev, PhD student, SPbSU
>
> --
> 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] Redex, traces and Graphviz

2015-09-23 Thread Anton Podkopaev
Hello!

I'm working on an operational semantics using PLT Redex. I use `traces` a lot 
to debug my semantics. To represent states in a nice way I'm using a pretty 
printer, but I want more -- I want to use Graphviz. Is it somehow possible to 
call Graphviz from my pretty printer, and incorporate a result of rendering 
into a pretty-printed text?

BR,
Anton Podkopaev, PhD student, SPbSU

-- 
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] Question about structuring recursive code

2015-09-23 Thread Kaushik Ghose
Thank you very much for your help! Best -Kaushik

On Wed, Sep 23, 2015 at 12:26 PM, Pierpaolo Bernardi 
wrote:

> On Wed, Sep 23, 2015 at 6:18 PM, Kaushik Ghose 
> wrote:
>
> > Can I have any statements in this block that I could have in a (define
> ...)
> > block? Can I have (defines ) for example?
>
> Yes, and yes  :)
>

-- 
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] Question about structuring recursive code

2015-09-23 Thread Pierpaolo Bernardi
On Wed, Sep 23, 2015 at 6:18 PM, Kaushik Ghose  wrote:

> Can I have any statements in this block that I could have in a (define ...)
> block? Can I have (defines ) for example?

Yes, and yes  :)

-- 
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] Question about structuring recursive code

2015-09-23 Thread Kaushik Ghose
Hi!

Thanks for your reply.


> (define (f-recur x y)
>   (cond ((< x 1)
>  10)
> (else
>... something complex
>   (f-recur x' y'
>

Can I have any statements in this block that I could have in a (define ...)
block? Can I have (defines ) for example?
Thanks!
-Kaushik

-- 
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] Question about structuring recursive code

2015-09-23 Thread Pierpaolo Bernardi
On Wed, Sep 23, 2015 at 3:20 PM, Kaushik Ghose  wrote:

> e.g.
>
> (define (f-recur x y)
> (if (< x 1)
> 10
> (f-recur-2 x y)))
>
> (define (f-recur-2 x y)
>   ... something complex here
>   (f-recur x' y')

(define (f-recur x y)
  (cond ((< x 1)
 10)
(else
   ... something complex
  (f-recur x' y'

-- 
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] Generating preorders

2015-09-23 Thread Erich Rast
You've just saved my day!

Thanks a lot!

Best,

Erich

On Wed, 23 Sep 2015 10:38:07 -0400
Josh Grams  wrote:

> On 2015-09-23 09:46AM, Erich Rast wrote:
> >Someone on stackoverflow gave me a working implementation in Python 3
> >
> >https://stackoverflow.com/questions/3269/
> >
> >but it uses advanced features and I have no clue how to translate
> >this to Racket.
> 
> Like this?
> 
> #lang racket
> 
> (define combinations   ; from Rosetta code
>   (match-lambda**
>[(_ 0)   '(())]
>[('() _) '()]
>[((cons x xs) m) (append
>  (map (curry cons x) (combinations xs (- m 1))) 
>  (combinations xs m))]))
> 
> (define (preorders A)
>   (if (null? A) '(())
>   (for*/fold ([result '()])
>  ([k (range 1 (+ 1 (length A)))]
>   [B (combinations A k)]
>   [order (preorders (set-subtract A B))])
> (cons (cons B order) result
> 

-- 
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] Generating preorders

2015-09-23 Thread Josh Grams
On 2015-09-23 09:46AM, Erich Rast wrote:
>Someone on stackoverflow gave me a working implementation in Python 3
>
>https://stackoverflow.com/questions/3269/
>
>but it uses advanced features and I have no clue how to translate this
>to Racket.

Like this?

#lang racket

(define combinations   ; from Rosetta code
  (match-lambda**
   [(_ 0)   '(())]
   [('() _) '()]
   [((cons x xs) m) (append
 (map (curry cons x) (combinations xs (- m 1))) 
 (combinations xs m))]))

(define (preorders A)
  (if (null? A) '(())
  (for*/fold ([result '()])
 ([k (range 1 (+ 1 (length A)))]
  [B (combinations A k)]
  [order (preorders (set-subtract A B))])
(cons (cons B order) result

-- 
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] Scribble: Typeset equations using Latex packages amsmath and amssym

2015-09-23 Thread Alexander D. Knauth

> On Sep 23, 2015, at 8:53 AM, Marc Kaufmann  wrote:

> #lang racket/base
> 
> (require scribble/base
> scribble/core)
> 
> (provide equation*)
> 
> (define (mymath start end . strs)
>  (make-element (make-style "relax" '(exact-chars)) `(,start ,@strs ,end)))
> 
> (define (equation* . strs)
>  (apply mymath "\\begin{equation*}" "\\end{equation*}" strs))
> 
> 
> 
> I still do not understand why I have to type "\\" rather than "\". I get that 
> something somewhere is escaping the backslash. I am uncomfortable with this, 
> as it seems that "{" and "}" are not escaped, but since I do not know what is 
> and what isn't, I may at some point in the future get a cryptic error message 
> because I used a command or a character in the strings that gets unescaped.

To avoid dealing with escapes like that, you could use the raw-string package, 
which lets you do this:
raco pkg install raw-string

#lang raw-string/raw-string racket/base #\$

(require scribble/base
 scribble/core)

(provide equation*)

(define (mymath start end . strs)
  (make-element (make-style "relax" '(exact-chars)) `(,start ,@strs ,end)))

(define (equation* . strs)
  (apply mymath $[\begin{equation*}] $[\end{equation*}] strs))

Those don't have to be [] brackets, they could be (), {}, <>, "", '', ^^, or 
any other pair of characters, as long as you don't try to put the ending 
character in the string.

You could also use at-exp for that, but raw-string is simpler.

-- 
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] Re: More Racket Place abuse^H^H^H^H^H issues

2015-09-23 Thread Tim Brown
I have installed the patch, and my installation is now passing its stress
test.

FYI, I put a quick printf() in to show when the bc->link is null (i.e. when
the bug would have manifested) -- it occurred 3 times in a run of 10M messages.

Rare, indeed.

Thanks for deaing with this so promptly.

Tim

On Tuesday, September 22, 2015 at 11:48:16 PM UTC+1, Matthew Flatt wrote:
> I found and repaired one bug that would explain all the crashes I've
> seen so far today. It's not a new bug, so I don't know why it would
> have escaped detection before.

-- 
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] Question about structuring recursive code

2015-09-23 Thread Kaushik Ghose
Hi Folks,

In recursive functions there is a termination clause that the function first 
tests for before proceeding. If the test clause succeeds an immediate value is 
returned, otherwise, a recursive call is made with some modification of input 
values.

In much code the body of the recursive function has several steps. In languages 
like python, the if clause is simply put at the head of the function and the 
rest of the body is written as usual. In Racket I find myself having to define 
a second function in order to do this, since what can go in the branches of an 
'if' statement are limited.

Is this the correct pattern, or is there a more elegant way of doing this in 
racket?

e.g.

(define (f-recur x y)
(if (< x 1)
10
(f-recur-2 x y)))

(define (f-recur-2 x y)
  ... something complex here
  (f-recur x' y')

Many thanks!
-Kaushik

-- 
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] Scribble: Typeset equations using Latex packages amsmath and amssym

2015-09-23 Thread Marc Kaufmann
Hi all,

I had a hard time to get any equations into my scribble document, as writing 

\begin{equation*} f(x) = x^2 \end{equation*}

would be turned into "$\backslash$begin...", which meant that it wouldn't 
actually show up as an equation but as garbage text with "begin{equation*}" and 
so on showing up. Since I found a way of getting it to work, I wanted to 
document it in baby steps that my 2-hours younger self would have understood 
faster than the links I found. Plus, I may be missing even easier solutions. 

The first problem with regards to equations in Latex is that Scribble 
(understandably) escapes some characters such as \ and $, so that Latex never 
sees the \begin, but $\backslash$. The second is to tell Scribble to load the 
Latex packages amsmath and amssymb. 

The solution to the first is to use Prabhakar Ragde's solution (see an example 
of it at https://gist.github.com/spdegabrielle/c9c9964d3e2fb4faa268). To get 
equation* working for instance, make a new file math.rkt (works for Latex only, 
for HTML see end of email, also from the above github link):



#lang racket/base

(require scribble/base
 scribble/core)

(provide equation*)

(define (mymath start end . strs)
  (make-element (make-style "relax" '(exact-chars)) `(,start ,@strs ,end)))

(define (equation* . strs)
  (apply mymath "\\begin{equation*}" "\\end{equation*}" strs))



I still do not understand why I have to type "\\" rather than "\". I get that 
something somewhere is escaping the backslash. I am uncomfortable with this, as 
it seems that "{" and "}" are not escaped, but since I do not know what is and 
what isn't, I may at some point in the future get a cryptic error message 
because I used a command or a character in the strings that gets unescaped.

Anway, once I do this, I can require math.rkt in my .scrbl file:



#lang scribble/base

@(require "math.rkt") ; Assumes math.rkt is in the same folder as .scrbl file

@title{Scribbling Equations}

@section{Equations at Work}

@equation*{f(x) = x^2}



To solve the second problem, make a new prefix file, math-prefix.tex:

---

\documentclass{article}

\usepackage[utf8]{inputenc} ; from standard prefix file
\usepackage[T1]{fontenc} ; from standard prefix file
\usepackage{amsmath} ; Required for equation*
\useapackage{amssymb} ; Required for a bunch of mathematical symbols

---

Finally, run the following on the command line:

scribble --prefix math-prefix.tex --pdf equations.scrbl

This worked for me. Is this the right way of loading extra packages? And when 
defining new mathematical commands in this way, what characters that might get 
escaped do I have to worry about? 

As for getting it to work with HTML, one should add the following to the 
math.rkt file:

--- 

#lang racket/base
; From http://con.racket-lang.org/pr-slides.pdf
; by Prabhakar Ragde
(require scribble/html-properties ; THIS IS NEW
 scribble/base
 scribble/core)

(provide ...)

; ADD THIS: It defines the link to MathJax, a library which turns Latex math 
; into proper form on websites
(define mathjax-source
  
"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"; 
  )

; By using @setup-math in your .scrbl file, this loads the mathjax library
(define setup-math
  (paragraph 
   (style 
#f (list (alt-tag "script")
 (attributes `((type . "text/javascript")
   (src . ,mathjax-source )
   '()))

---

Thanks for reading this far. And just to be clear, I am not taking credit for 
this solution, but I found the existing links to be unclear, and only 
addressing one part of the problem, which meant that I wasn't even sure what 
went wrong when it did. Hope this helps someone.

Cheers,
Marc

-- 
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] Generating preorders

2015-09-23 Thread Erich Rast
Thanks Robby and Vincent for the advice. Yes, I should have been more
precise, I need to generate all *total preorders* of a given size. The
task is equivalent to generating all weak orders.

I think my idea to do this on the basis of permutations is flawed
and I'll start from scratch but it would be helpful if I could find a
reference to an algorithm. Someone on stackoverflow gave me a working
implementation in Python 3

https://stackoverflow.com/questions/3269/

but it uses advanced features and I have no clue how to translate this
to Racket.

Best,

Erich

-- 
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.