Re: [racket-users] Package documentation category with info.rkt

2016-02-09 Thread Erik Silkensen
Sorry, last email --- Guess I did have a multi collection setup, after all, and 
forgot there was a second info.rkt inside that yaml subdirectory.  So the only 
change I needed was to add the parsing-library category to scribblings in the 
yaml/yaml/info.rkt.

> On Feb 9, 2016, at 3:47 AM, Erik Silkensen  wrote:
> 
> Cool, I think that does it.  I think I had a bad directory structure.  It was
> 
> yaml/info.rkt
> yaml/yaml/main.rkt
> yaml/yaml/yaml.scrbl
> etc.
> 
> If move everything in that yaml subdirectory up, then using
> 
> #lang info
> 
> (define collection "yaml")
> (define deps '("base" "srfi-lite-lib" "typed-racket-lib"))
> (define build-deps '("rackunit-lib" "scribble-lib" "racket-doc" 
> "sandbox-lib"))
> (define scribblings '(("yaml.scrbl" () (parsing-library
> 
> gets the link under “Parsing Libraries” with JSON and the rest.
> 
> (Using “Parsing Libraries” as the category creates a duplicate category with 
> just YAML)
> 
> Anyway, thanks for your help!
> 
>> On Feb 9, 2016, at 3:07 AM, Benjamin Greenman > <mailto:benjaminlgreen...@gmail.com>> wrote:
>> 
>> Hm. I'm not sure what's going on.
>> 
>> If I make a package with your info file, I get no links in the docs. But 
>> changing the collection to "yaml" generates documentation under the "Parsing 
>> Libraries" category.
>> 
>> Can you use "yaml" instead of 'multi ?
>> 
>> On Tue, Feb 9, 2016 at 3:33 AM, Erik Silkensen > <mailto:eriksilken...@gmail.com>> wrote:
>> Thanks, Ben.  I think I’m still missing something, still get the same 
>> result.  In case it helps, here’s my complete info.rkt:
>> 
>> #lang info
>> 
>> (define collection 'multi)
>> (define deps '("base" "srfi-lite-lib" "typed-racket-lib"))
>> (define build-deps '("rackunit-lib" "scribble-lib" "racket-doc" 
>> "sandbox-lib"))
>> (define scribblings '(("yaml/yaml.scrbl" () ("Parsing Libraries"
>> 
>>> On Feb 9, 2016, at 1:03 AM, Benjamin Greenman >> <mailto:benjaminlgreen...@gmail.com>> wrote:
>>> 
>>> Yep, use a string instead of a symbol:
>>> 
>>> (define scribblings '(("yaml/yaml.scrbl" () ("Parsing Libraries"
>>> 
>>> The only valid symbols are the category names listed here [1].
>>> 
>>> [1] http://docs.racket-lang.org/raco/setup-info.html?q=info 
>>> <http://docs.racket-lang.org/raco/setup-info.html?q=info>
>>> 
>>> On Tue, Feb 9, 2016 at 2:39 AM, Erik Silkensen >> <mailto:eriksilken...@gmail.com>> wrote:
>>> Hi Racket users,
>>> 
>>> I'm wondering how to control the documentation category for user-defined 
>>> packages?  For example, I've created a YAML package and would like it to 
>>> show up under "Parsing Libraries".  I tried setting
>>> 
>>> (define scribblings '(("yaml/yaml.scrbl" () (parsing-library
>>> 
>>> in info.rkt, but after installing the package the link is under 
>>> "Miscellaneous Libraries".
>>> 
>>> Is there a way to do this?
>>> 
>>> 
>>> Cheers,
>>> 
>>> Erik
>>> 
>>> --
>>> 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 
>>> <mailto:racket-users%2bunsubscr...@googlegroups.com>.
>>> For more options, visit https://groups.google.com/d/optout 
>>> <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] Package documentation category with info.rkt

2016-02-09 Thread Erik Silkensen
Cool, I think that does it.  I think I had a bad directory structure.  It was

yaml/info.rkt
yaml/yaml/main.rkt
yaml/yaml/yaml.scrbl
etc.

If move everything in that yaml subdirectory up, then using

#lang info

(define collection "yaml")
(define deps '("base" "srfi-lite-lib" "typed-racket-lib"))
(define build-deps '("rackunit-lib" "scribble-lib" "racket-doc" "sandbox-lib"))
(define scribblings '(("yaml.scrbl" () (parsing-library

gets the link under “Parsing Libraries” with JSON and the rest.

(Using “Parsing Libraries” as the category creates a duplicate category with 
just YAML)

Anyway, thanks for your help!

> On Feb 9, 2016, at 3:07 AM, Benjamin Greenman  
> wrote:
> 
> Hm. I'm not sure what's going on.
> 
> If I make a package with your info file, I get no links in the docs. But 
> changing the collection to "yaml" generates documentation under the "Parsing 
> Libraries" category.
> 
> Can you use "yaml" instead of 'multi ?
> 
> On Tue, Feb 9, 2016 at 3:33 AM, Erik Silkensen  <mailto:eriksilken...@gmail.com>> wrote:
> Thanks, Ben.  I think I’m still missing something, still get the same result. 
>  In case it helps, here’s my complete info.rkt:
> 
> #lang info
> 
> (define collection 'multi)
> (define deps '("base" "srfi-lite-lib" "typed-racket-lib"))
> (define build-deps '("rackunit-lib" "scribble-lib" "racket-doc" 
> "sandbox-lib"))
> (define scribblings '(("yaml/yaml.scrbl" () ("Parsing Libraries"
> 
>> On Feb 9, 2016, at 1:03 AM, Benjamin Greenman > <mailto:benjaminlgreen...@gmail.com>> wrote:
>> 
>> Yep, use a string instead of a symbol:
>> 
>> (define scribblings '(("yaml/yaml.scrbl" () ("Parsing Libraries"
>> 
>> The only valid symbols are the category names listed here [1].
>> 
>> [1] http://docs.racket-lang.org/raco/setup-info.html?q=info 
>> <http://docs.racket-lang.org/raco/setup-info.html?q=info>
>> 
>> On Tue, Feb 9, 2016 at 2:39 AM, Erik Silkensen > <mailto:eriksilken...@gmail.com>> wrote:
>> Hi Racket users,
>> 
>> I'm wondering how to control the documentation category for user-defined 
>> packages?  For example, I've created a YAML package and would like it to 
>> show up under "Parsing Libraries".  I tried setting
>> 
>> (define scribblings '(("yaml/yaml.scrbl" () (parsing-library
>> 
>> in info.rkt, but after installing the package the link is under 
>> "Miscellaneous Libraries".
>> 
>> Is there a way to do this?
>> 
>> 
>> Cheers,
>> 
>> Erik
>> 
>> --
>> 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 
>> <mailto:racket-users%2bunsubscr...@googlegroups.com>.
>> For more options, visit https://groups.google.com/d/optout 
>> <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] Package documentation category with info.rkt

2016-02-09 Thread Erik Silkensen
Thanks, Ben.  I think I’m still missing something, still get the same result.  
In case it helps, here’s my complete info.rkt:

#lang info

(define collection 'multi)
(define deps '("base" "srfi-lite-lib" "typed-racket-lib"))
(define build-deps '("rackunit-lib" "scribble-lib" "racket-doc" "sandbox-lib"))
(define scribblings '(("yaml/yaml.scrbl" () ("Parsing Libraries"

> On Feb 9, 2016, at 1:03 AM, Benjamin Greenman  
> wrote:
> 
> Yep, use a string instead of a symbol:
> 
> (define scribblings '(("yaml/yaml.scrbl" () ("Parsing Libraries"
> 
> The only valid symbols are the category names listed here [1].
> 
> [1] http://docs.racket-lang.org/raco/setup-info.html?q=info 
> <http://docs.racket-lang.org/raco/setup-info.html?q=info>
> 
> On Tue, Feb 9, 2016 at 2:39 AM, Erik Silkensen  <mailto:eriksilken...@gmail.com>> wrote:
> Hi Racket users,
> 
> I'm wondering how to control the documentation category for user-defined 
> packages?  For example, I've created a YAML package and would like it to show 
> up under "Parsing Libraries".  I tried setting
> 
> (define scribblings '(("yaml/yaml.scrbl" () (parsing-library
> 
> in info.rkt, but after installing the package the link is under 
> "Miscellaneous Libraries".
> 
> Is there a way to do this?
> 
> 
> Cheers,
> 
> Erik
> 
> --
> 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 
> <mailto:racket-users%2bunsubscr...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout 
> <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] Package documentation category with info.rkt

2016-02-08 Thread Erik Silkensen
Hi Racket users,

I'm wondering how to control the documentation category for user-defined 
packages?  For example, I've created a YAML package and would like it to show 
up under "Parsing Libraries".  I tried setting

(define scribblings '(("yaml/yaml.scrbl" () (parsing-library

in info.rkt, but after installing the package the link is under "Miscellaneous 
Libraries".

Is there a way to do this?


Cheers,

Erik

-- 
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] eval and set

2015-04-04 Thread Erik Silkensen
Could someone explain how this example works?

$ racket
Welcome to Racket v6.1.1.
-> (require racket/sandbox)
-> (define racket-eval (make-evaluator 'racket))
-> (define a (racket-eval '(set 1 2 3)))
-> a
(set 1 2 3)
-> (set? a)
#f
-> (define racket-eval-again (make-evaluator 'racket))
-> (equal? a (racket-eval-again '(set 1 2 3)))
#f

Is it something particular to set?  (Or objects like that?)

--Erik

-- 
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] Macro question - `let' without inferring name?

2012-09-05 Thread Erik Silkensen
Cool, thanks!

Erik

On Sep 6, 2012, at 12:08 AM, Eric Dobson  wrote:

> How about:
> 
> (define-syntax (m stx)
>  (syntax-case stx ()
>[(m expr)
> #'(let ([t (values expr)])
> ;; 
> t)]))
> 
> Which seems to work for me.
> 
> On Wed, Sep 5, 2012 at 8:56 PM, Erik Silkensen  
> wrote:
>> Hi,
>> 
>> I'm wondering if there's any way to have a macro like
>> 
>> (define-syntax (m stx)
>>  (syntax-case stx ()
>>[(m expr)
>> #'(let ([t expr])
>> ;; 
>> t)]))
>> 
>> that binds expr to t, does some things, and then somehow returns t -- but 
>> with whatever name would have been inferred for expr without the let, and 
>> not 't' (if that makes sense?)
>> 
>> Thanks,
>> Erik
>> 
>>  Racket Users list:
>>  http://lists.racket-lang.org/users



  Racket Users list:
  http://lists.racket-lang.org/users


[racket] Macro question - `let' without inferring name?

2012-09-05 Thread Erik Silkensen
Hi,

I'm wondering if there's any way to have a macro like

(define-syntax (m stx)
  (syntax-case stx ()
[(m expr)
 #'(let ([t expr])
 ;; 
 t)]))

that binds expr to t, does some things, and then somehow returns t -- but with 
whatever name would have been inferred for expr without the let, and not 't' 
(if that makes sense?)

Thanks,
Erik

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] how to define-predicate for a recursive type?

2012-08-08 Thread Erik Silkensen
Hi,

The code 

#lang typed/racket

(define-type IntList (Rec List (Pair Integer (U List Null
(define-predicate int-list? IntList)

> (int-list? '(1 2 3))

gives the runtime error: 

recursive-contract: expected a flat contract or a value that can be coerced 
into one, got #

Is there a way to generate a predicate for a type like this?

Thanks,
Erik

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] unwrapping a list

2012-06-11 Thread Erik Silkensen
You could use match or match-let, e.g.,

(match-let ([(list year month day) (regexp-split #rx"/" "2012/06/06")])
  …)

http://docs.racket-lang.org/reference/match.html

On Jun 11, 2012, at 8:24 PM, Jordan Schatz wrote:

> 
> Is there a way to unwrap or explode a list? I don't see it in the docs, but it
> seems like it would be a common thing.
> 
> This is what I want to do:
> 
> (define-values (year month day)
>  (regexp-split #rx"/" "2012/06/06"))
> 
> But regexp-split returns a list, not values, so I'd like to "unwrap" the list
> and just have the values...
> 
> I can do it manually:
> (define tmp (regexp-split #rx"/" "2012/06/06"))
> (define year (first tmp))
> (define month (second tmp))
> (define day (third tmp))
> 
> But thats ugly.
> 
> Being able to 
> (let ([year month day (regexp-split #rx"/" "2012/06/06")])
>  )
> Would be handy too...
> 
> - Jordan
> 
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users



  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] looking for a twitter library (or, failing that, OAuth 1.0)

2012-05-21 Thread Erik Silkensen
The arc page is out of date -- it will run with the MzScheme included in the 
current Racket download 
(https://sites.google.com/site/arclanguagewiki/getting-started/install-arc)

On May 21, 2012, at 12:37 AM, Marijn wrote:

> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
> 
> On 14-05-12 08:03, Zachary Kanfer wrote:
>> I'd like to write a program (in Arc, which is a language on top of
>> Racket)
> 
> Reading this I thought I'd see whether there is any truth to it, but
> http://arclanguage.org/install still claims that you need MzScheme
> 372, so no Racket there.
> 
> Marijn
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v2.0.19 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> 
> iEYEARECAAYFAk+54o4ACgkQp/VmCx0OL2wmuQCfWyrfKBydrmtL7ntKxiivWyIf
> D4cAoJIj4pNTy4mqa31q80hFqSBhxH/s
> =TDvO
> -END PGP SIGNATURE-
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users



  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] DrRacket and The Little Schemer?

2012-05-20 Thread Erik Silkensen
Try just the Racket language by putting "#lang racket" at the top of your file.

On May 20, 2012, at 9:09 PM, Olwe Melwasul wrote:

> I've been working through The Little Schemer using Petite Chez Scheme and 
> Emacs, but now I'd like to try DrRacket. I have a large file where I've been 
> putting all the function defines from the book. Occasionally, I use my own 
> function names, but mostly I stick with the book's names. My problem is that 
> when I click Run, errors appear:
> 
> add1: this name was defined previously and cannot be re-defined
> 
> This happens with all the HTDP language choices. With the Legacy languages I 
> get:
> 
> define-values: cannot change constant variable: equal?
> 
> Of course commenting out seems to get me farther, but I'm commenting so many 
> out! I'd simply like to try DrRacket with TLS and be able to debug and step 
> through my code. For example, I'd like to find a way to trace through each 
> step of evens-only*&co
> 
> 
> 
> 
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users



  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Are There More String Functions?

2012-04-11 Thread Erik Silkensen
As far as I know it should be fine to just use a mix of the built-in and 
srfi/13 functions.

-- Erik

On Apr 11, 2012, at 11:25 PM, Cristian Esquivias wrote:

> Hi Erik,
> 
> Thanks for the library. Should I be calling (require srfi/13) or
> import only the functions I want? That is, can I use a mix of the
> built-in Racket string functions and srfi/13 functions, or will I have
> to migrate completely to the srfi/13 functions?
> 
> - Cristian
> 
> On Wed, Apr 11, 2012 at 10:06 PM, Erik Silkensen
>  wrote:
>> Hi Cristian,
>> 
>> Check out SRFI 13: http://docs.racket-lang.org/srfi-std/srfi-13.html
>> 
>> You can load it in Racket with (require srfi/13)
>> 
>> -- Erik
>> 
>> On Apr 11, 2012, at 10:57 PM, Cristian Esquivias wrote:
>> 
>>> I just started getting my hands dirty with Racket on some utility
>>> scripts. Overall, it's been a great experience. My scripts are
>>> shorter, clearer and faster than the initial Python scripts I wrote
>>> (but that could be because they're my second time around).
>>> 
>>> I did run into one constant obstacle while using Racket: the dearth of
>>> convenience string functions. There are plenty of functions for
>>> strings, but several functions that are present on other platforms
>>> (e.g., Python, Ruby, Java, etc.) don't seem to be part of the Racket
>>> standard library.
>>> 
>>> Some of the functions I couldn't find but would've been useful were
>>> things like (in Racket-type naming):
>>> 
>>> string-starts-with?
>>> string-ends-with?
>>> string-index-of
>>> string-replace
>>> string-trim
>>> 
>>> I did a little google searching and most advice said to use the regex
>>> library (which I did), but the code isn't as clear had I used
>>> functions like the ones above.
>>> 
>>> Do these functions exist anywhere? Is there a great PLaneT package
>>> that supplies these functions?
>>> 
>>> Thanks,
>>> Cristian
>>> 
>>>  Racket Users list:
>>>  http://lists.racket-lang.org/users
>> 



  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Are There More String Functions?

2012-04-11 Thread Erik Silkensen
Hi Cristian,

Check out SRFI 13: http://docs.racket-lang.org/srfi-std/srfi-13.html

You can load it in Racket with (require srfi/13)

-- Erik

On Apr 11, 2012, at 10:57 PM, Cristian Esquivias wrote:

> I just started getting my hands dirty with Racket on some utility
> scripts. Overall, it's been a great experience. My scripts are
> shorter, clearer and faster than the initial Python scripts I wrote
> (but that could be because they're my second time around).
> 
> I did run into one constant obstacle while using Racket: the dearth of
> convenience string functions. There are plenty of functions for
> strings, but several functions that are present on other platforms
> (e.g., Python, Ruby, Java, etc.) don't seem to be part of the Racket
> standard library.
> 
> Some of the functions I couldn't find but would've been useful were
> things like (in Racket-type naming):
> 
> string-starts-with?
> string-ends-with?
> string-index-of
> string-replace
> string-trim
> 
> I did a little google searching and most advice said to use the regex
> library (which I did), but the code isn't as clear had I used
> functions like the ones above.
> 
> Do these functions exist anywhere? Is there a great PLaneT package
> that supplies these functions?
> 
> Thanks,
> Cristian
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Any way to get "true" quasiquote behavior in match form?

2012-03-09 Thread Erik Silkensen
I wonder if define-match-expander might be what you're looking for?  
http://docs.racket-lang.org/reference/match.html?q=define-match-expander#(form._((lib._racket/match..rkt)._define-match-expander))

Erik

On Mar 9, 2012, at 8:22 PM, rob cook wrote:

> Thanks for the tips - I am new to using match, the answers are illuminating, 
> and so close...
> 
> I perhaps oversimplified my example. What I actually need to do is to match 
> on an arbitrary expression bound earlier., e.g.
> 
> (match foo
> (bar #t)
> (_ #f))
> 
> Where bar is bound to some valid *match* expression. It appears the ==  fits 
> the bill for something that resolves to some literal value in the end. I need 
> to match what might be a literal, but could be something like bar being  
> (list (and (? number?) (? odd?.
> 
> In other words, I'd like to be able to generate or have the user supply any 
> arbitrary match expression, and use it for the bar in the match shown above. 
> Ideas?
> 
> Thx again,
> Rob
> 
> On Fri, Mar 9, 2012 at 4:37 PM, rob cook  wrote:
> That is, without using a macro or eval. Id like to do:
> 
> (define a 4)
> (define l1 '(1 2 3))
> (match l1
>   (`(1 2 ,a) #t)
>   (_ #f))
> 
> So that this example would result in #f, and #t if a bound to 3.
> 
> Since of course match has its own quasiquote behavior, this does not seem 
> possible w/o making a macro for "dynamic" match, or building the s-exp and 
> using eval (yuck!).
> 
> Is this correct, or have I missed something obvious?
> 
> Thnx
> Rob
> 
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Making a Racket function "recallable"

2012-02-14 Thread Erik Silkensen
Sure, sounds good.

The (let loop ([vs '()]) ...) is a 'named let' 
(http://docs.racket-lang.org/guide/let.html?q=named%20let#(part._.Named_let)) 
which as the guide says is equivalent to (letrec ([loop (lambda (vs) ...)]) 
(loop '()) --- so 'loop' is a recursive function that we're using to iterate 
until (fib) is >= n, accumulating the values in the vs argument.  If you're not 
familiar with letrec, another definition would be

(define (fib-less-than-n n)
  (define fib (mk-fib))
  (define (loop vs)
(let ([fib-val (fib)])
  (if (>= fib-val n)
  (reverse vs)
  (loop (cons fib-val vs)
  (loop '()))



Thinking of loops as just a form of recursion can be a little strange at first. 
 There's more information in the Racket guide here- 
http://docs.racket-lang.org/guide/Lists__Iteration__and_Recursion.html or 
another page to check out might be 
http://mitpress.mit.edu/sicp/full-text/sicp/book/node15.html. 

Hope this helps,

- Erik


On Feb 14, 2012, at 1:00 AM, Joe Gilray wrote:

> Thanks Erik.  Very nice!  Although I miss the recursion.
> 
> please help me understand how this works, especially (let loop ([vs '()]). 
> What exactly is going on there?
> 
> Thanks again,
> -joe
> 
> On Mon, Feb 13, 2012 at 9:51 PM, Erik Silkensen  
> wrote:
> Instead of calling fib-less-than-n recursively, you could add a loop inside, 
> for example something like,
> 
> (define (fib-less-than-n n)
>   (define fib (mk-fib))
>   (let loop ([vs '()])
> (let ([fib-val (fib)])
>   (if (>= fib-val n)
>   (reverse vs)
>   (loop (cons fib-val vs))
> 
> - Erik
> 
> On Feb 13, 2012, at 10:41 PM, Joe Gilray wrote:
> 
>> Erik,
>> 
>> Intriguing idea and it works "flat", but if I write the following I end up 
>> with an infinite loop:
>> 
>> (define (fib-less-than-n n)
>>   (let ([f1 (mk-fib)])
>> (let ([fib-val (f1)])
>>   (if (>= fib-val n) '() (cons fib-val (fib-less-than-n n))
>> 
>> How would I use your idea in this case?
>> 
>> thanks!
>> -joe
>> 
>> On Mon, Feb 13, 2012 at 9:18 PM, Erik Silkensen  
>> wrote:
>> Another option is you could turn change your fib function to be 'mk-fib' 
>> that returns a new instance of the fib function each time it's called:
>> 
>> (define (mk-fib)
>>  (let ([n0 -1] [n1 1])
>>(lambda ()
>>  (let ([next (+ n0 n1)])
>>(set! n0 n1)
>>(set! n1 next))
>>  n1)))
>> 
>> - Erik
>> 
>> On Feb 13, 2012, at 10:10 PM, Danny Yoo wrote:
>> 
>> > On Mon, Feb 13, 2012 at 11:52 PM, Joe Gilray  wrote:
>> >> Warning: extreme newbie question ahead.
>> >>
>> >> I wrote the following fibonacci function:
>> >>
>> >> ; function that returns the next fibonacci number each time it is called
>> >> ; invoke as (fib)
>> >> (define fib
>> >>   (let ([n0 -1] [n1 1])
>> >> (lambda ()
>> >>   (let ([next (+ n0 n1)])
>> >> (set! n0 n1)
>> >> (set! n1 next))
>> >>   n1)))
>> >
>> >
>> > One thing you can do is turn fib into a "sequence", and then from a
>> > sequence into a stream that knows how to remember its previous values.
>> >
>> > Here's what it might look like:
>> >
>> > ;;
>> > #lang racket
>> > (require racket/sequence)
>> >
>> > (define fib
>> >  (let ([n0 -1] [n1 1])
>> >(lambda ()
>> >  (let ([next (+ n0 n1)])
>> >(set! n0 n1)
>> >(set! n1 next))
>> >  n1)))
>> >
>> > (define fib-stream
>> >  ;; Here's a sequence of the function:
>> >  (let ([fib-sequence (in-producer fib 'donttellmecauseithurts)])
>> >
>> >;; Let's wrap it and turn it into a stream that remembers...
>> >(sequence->stream fib-sequence)))
>> >
>> >
>> > ;; Ok, we've got a stream.  Let's look at its first few elements.
>> > (define (peek-fibs n)
>> >  (for ([elt fib-stream]
>> >[i (in-range n)])
>> >(displayln elt)))
>> >
>> > (peek-fibs 10)
>> > (printf "-\n")
>> > (peek-fibs 20)
>> > ;;;
>> >
>> > 
>> >  Racket Users list:
>> >  http://lists.racket-lang.org/users
>> 
>> 
> 
> 


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Making a Racket function "recallable"

2012-02-13 Thread Erik Silkensen
Instead of calling fib-less-than-n recursively, you could add a loop inside, 
for example something like,

(define (fib-less-than-n n)
  (define fib (mk-fib))
  (let loop ([vs '()])
(let ([fib-val (fib)])
  (if (>= fib-val n)
  (reverse vs)
  (loop (cons fib-val vs))

- Erik

On Feb 13, 2012, at 10:41 PM, Joe Gilray wrote:

> Erik,
> 
> Intriguing idea and it works "flat", but if I write the following I end up 
> with an infinite loop:
> 
> (define (fib-less-than-n n)
>   (let ([f1 (mk-fib)])
> (let ([fib-val (f1)])
>   (if (>= fib-val n) '() (cons fib-val (fib-less-than-n n))
> 
> How would I use your idea in this case?
> 
> thanks!
> -joe
> 
> On Mon, Feb 13, 2012 at 9:18 PM, Erik Silkensen  
> wrote:
> Another option is you could turn change your fib function to be 'mk-fib' that 
> returns a new instance of the fib function each time it's called:
> 
> (define (mk-fib)
>  (let ([n0 -1] [n1 1])
>(lambda ()
>  (let ([next (+ n0 n1)])
>(set! n0 n1)
>(set! n1 next))
>  n1)))
> 
> - Erik
> 
> On Feb 13, 2012, at 10:10 PM, Danny Yoo wrote:
> 
> > On Mon, Feb 13, 2012 at 11:52 PM, Joe Gilray  wrote:
> >> Warning: extreme newbie question ahead.
> >>
> >> I wrote the following fibonacci function:
> >>
> >> ; function that returns the next fibonacci number each time it is called
> >> ; invoke as (fib)
> >> (define fib
> >>   (let ([n0 -1] [n1 1])
> >> (lambda ()
> >>   (let ([next (+ n0 n1)])
> >> (set! n0 n1)
> >> (set! n1 next))
> >>   n1)))
> >
> >
> > One thing you can do is turn fib into a "sequence", and then from a
> > sequence into a stream that knows how to remember its previous values.
> >
> > Here's what it might look like:
> >
> > ;;
> > #lang racket
> > (require racket/sequence)
> >
> > (define fib
> >  (let ([n0 -1] [n1 1])
> >(lambda ()
> >  (let ([next (+ n0 n1)])
> >(set! n0 n1)
> >(set! n1 next))
> >  n1)))
> >
> > (define fib-stream
> >  ;; Here's a sequence of the function:
> >  (let ([fib-sequence (in-producer fib 'donttellmecauseithurts)])
> >
> >;; Let's wrap it and turn it into a stream that remembers...
> >(sequence->stream fib-sequence)))
> >
> >
> > ;; Ok, we've got a stream.  Let's look at its first few elements.
> > (define (peek-fibs n)
> >  (for ([elt fib-stream]
> >[i (in-range n)])
> >(displayln elt)))
> >
> > (peek-fibs 10)
> > (printf "-\n")
> > (peek-fibs 20)
> > ;;;
> >
> > 
> >  Racket Users list:
> >  http://lists.racket-lang.org/users
> 
> 


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Making a Racket function "recallable"

2012-02-13 Thread Erik Silkensen
Another option is you could turn change your fib function to be 'mk-fib' that 
returns a new instance of the fib function each time it's called:

(define (mk-fib)
  (let ([n0 -1] [n1 1])
(lambda ()
  (let ([next (+ n0 n1)])
(set! n0 n1)
(set! n1 next))
  n1)))

- Erik

On Feb 13, 2012, at 10:10 PM, Danny Yoo wrote:

> On Mon, Feb 13, 2012 at 11:52 PM, Joe Gilray  wrote:
>> Warning: extreme newbie question ahead.
>> 
>> I wrote the following fibonacci function:
>> 
>> ; function that returns the next fibonacci number each time it is called
>> ; invoke as (fib)
>> (define fib
>>   (let ([n0 -1] [n1 1])
>> (lambda ()
>>   (let ([next (+ n0 n1)])
>> (set! n0 n1)
>> (set! n1 next))
>>   n1)))
> 
> 
> One thing you can do is turn fib into a "sequence", and then from a
> sequence into a stream that knows how to remember its previous values.
> 
> Here's what it might look like:
> 
> ;;
> #lang racket
> (require racket/sequence)
> 
> (define fib
>  (let ([n0 -1] [n1 1])
>(lambda ()
>  (let ([next (+ n0 n1)])
>(set! n0 n1)
>(set! n1 next))
>  n1)))
> 
> (define fib-stream
>  ;; Here's a sequence of the function:
>  (let ([fib-sequence (in-producer fib 'donttellmecauseithurts)])
> 
>;; Let's wrap it and turn it into a stream that remembers...
>(sequence->stream fib-sequence)))
> 
> 
> ;; Ok, we've got a stream.  Let's look at its first few elements.
> (define (peek-fibs n)
>  (for ([elt fib-stream]
>[i (in-range n)])
>(displayln elt)))
> 
> (peek-fibs 10)
> (printf "-\n")
> (peek-fibs 20)
> ;;;
> 
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users



  Racket Users list:
  http://lists.racket-lang.org/users


[racket] clarification for a Typed Racket error?

2012-01-05 Thread Erik Silkensen
Hi,

I was wondering if someone could help me understand the problem with the 
following code?

(struct: obj ([a : Integer] [b : Symbol]))

(: f1? (obj Symbol -> Boolean))
(define (f1? o x)
 (and (= 0 (obj-a o))
  (eq? x (obj-b o

(: f2? (obj Symbol -> Boolean))
(define (f2? o x)
 (and (zero? (obj-a o))
  (eq? x (obj-b o

(: f3? (obj Symbol -> Boolean))
(define (f3? o x)
 (and (eq? x (obj-b o))
  (zero? (obj-a o

It looks like f1 and f3 are ok, but f2 has the error "Type Checker: Expected 
obj, but got #(struct:# ((U Inexact-Complex Real-Zero) Symbol)) 
in: o".

Thanks,
Erik

  Racket Users list:
  http://lists.racket-lang.org/users