Re: [racket-users] simple question about call/cc

2020-12-07 Thread Justin Zamora
The duplication is because you're evaluating the expression at top
level, so the repl is part of the continuation. The continuation isn't
(lambda (c) (c e2); it's actually something like (lambda (c)
(evaluate-in-repl (c e2)). So when you run (ret 9), you're actually
re-running the repl you had when you evaluated the expression, which
leads to the duplication.

To avoid this, put the expression in a procedure:

#lang racket
(define ret #f)
(define ret2 (lambda (c) (add1 c)))

(define (haha)
  (add1
   (call/cc
(lambda (k)
  (set! ret k) ;; Now ret should be equivalent to ret2.
  2

Then you get what you expect, because the continuation is delimited by
the procedure definition:

Welcome to DrRacket, version 7.8 [3m].
Language: racket, with debugging; memory limit: 128 MB.
> (haha)
3
> (ret 9)
10
> (ret2 5)
6

On Mon, Dec 7, 2020 at 9:26 PM Tim Meehan  wrote:
>
> I've read a lot about call/cc, and each time wind up just moving on. So this 
> is an early New Year's resolution: getting a better understanding of it.
>
> According to Wikipedia's page on continuations, the continuation of the 
> statement:
>
> ((call/cc f) e2)
>
> is:
>
> (lambda (c) (c e2))
>
> #lang racket
> (define ret #f)
> (define ret2 (lambda (c) (add1 c)))
>
> (add1
>  (call/cc
>   (lambda (k)
> (set! ret k) ;; Now ret should be equivalent to ret2.
> 2)))
>
> (ret 9) ;; Why does this print twice?
> (ret2 5) ;; This only prints once, like I would have expected.
>
> --
> 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.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/CACgrOx%2BnXZpQv_MbDwdAZJSGpMiD%2BE1gB4YH8Rsb_y3%3D6RaAnQ%40mail.gmail.com.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CA%2B80D0XpFgieuANWieS7NEoe%3DOHweZXsgB9wjvQmg1j-aggumQ%40mail.gmail.com.


Re: [racket-users] Racket GUI: text aligned to the left of other text

2020-08-10 Thread Justin Zamora
Another, less lightweight way is to use panels for different parts of
the chat windows. I put together a sample at
https://gist.github.com/zamora/1cfc6480f7703735dffa3169facfbf10

On Mon, Aug 10, 2020 at 3:32 PM Christopher Lemmer Webber
 wrote:
>
> Hello,
>
> I'm building a little chat application with Racket.  Overall Racket's
> GUI tools are quite comfortable, and I'm just using Rakcet's text editor
> stuff to build the chat.  But a fairly standard thing to do with chat
> applications is to have text like:
>
> (Beware, fixed width ascii art ahead)
>
>  ..
>  | FooChat Deluxe  [X]|
>  ||
>  | File  Blah |
>  ||
>  |  | It's snowing outside!! | alice   |
>  || In August  | bob |
>  |  | Nevermind, the snow is a representation of | carol   |
>  | | collective anxiety about the world | |
>  || Oh okay it is snowing then | |
>  ||
>  | [Better go get some snow shoes then___] [Send] |
>  ''
>
> The core idea there being that usernames left-align to the text.
>
> I'm not sure what's the nicest way to do this, though I've taken a guess
> that maybe the "Show/Hide Line Numbers" in DrRacket is the best example.
> I'd be happy to look at that but I can't really find it in the drracket
> repository and am not sure where it would be?
>
> (I guess one other complication is that if you copy-pasta text it would
> be great to still be able to copy paste the names too, but I can think
> of some kludgery that might make that possible.)
>
>  - Chris
>
> --
> 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.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/87lfime1pm.fsf%40dustycloud.org.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CA%2B80D0XvAXnGsWL8vEkOm4JGO50rad2rPWnqwc-ywODKPcGKww%40mail.gmail.com.


Re: [racket-users] How to implement a hash function for different types?

2019-08-02 Thread Justin Zamora
Racket doesn't implement hash tables using a hash function. If I
recall correctly, it uses b-trees as the representation for a hash
table.  The Racket reference states that "Immutable hash tables
actually provide O(log N) access and update. Since N is limited by the
address space so that log N is limited to less than 30 or 62
(depending on the platform), log N can be treated reasonably as a
constant." See. https://docs.racket-lang.org/reference/hashtables.html

Justin

On Fri, Aug 2, 2019 at 9:22 PM Jesse Wang  wrote:
>
> Racket allows different types of keys in a single hash, so there must be a 
> hash function that works for different types(different primitive types), I 
> wonder how Racket implements this under the hood.
> Also, If I want to implement a hash table which allows different types of 
> keys, how can I implement such a hash function in Racket?
>
> Thanks!
>
> --
> 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.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/ad183814-d9f1-454b-b1a2-d1a9b394f49d%40googlegroups.com.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CA%2B80D0W3sAX0h-QQvZ-6tiZZo6QFzNZNOGxxYhGHJ07LhtPVwQ%40mail.gmail.com.


[racket-users] [standard-fish] Lightsabers!

2019-07-30 Thread Justin Zamora
[Apologies if this gets sent twice. I accidentally sent the first one
to the googlegroups email address]

Stephen De Gabrielle announced this a few days ago on racket-dev, so I
spent my weekend embracing my inner Star Wars nerd and made
lightsabers in Racket. I had never used the pict library before, so it
was also an interesting learning experience.

I created a lightsaber function that produces a pict of a lightsaber.
The only required argument is a color, which can be either a color
name or a color% object. A length can be provided as an optional
argument, as well as a style for the lightsaber hilt. The default hilt
is Luke Skywalker's (#:style 'luke), but you can also select Darth
Vader's (#:style 'vader), Kylo Ren's (#:style 'kylo), or Darth Maul's
(#:style 'maul). See the attached picture for examples of each.

The code is available at https://github.com/zamora/lightsaber

Thanks to Stephen De Gabrielle for providing the incentive to learn
about pict and have some fun!

Justin

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CA%2B80D0WkdQR0ExV0zZU2XGBj9ifGmaewLTi7utk2fqMJkUdNew%40mail.gmail.com.


[racket-users] [standard-fish] Lightsabers!

2019-07-30 Thread Justin Zamora
Stephen De Gabrielle announced this a few days ago on racket-dev, so I
spent my weekend embracing my inner Star Wars nerd and made
lightsabers in Racket. I had never used the pict library before, so it
was also an interesting learning experience.

I created a lightsaber function that produces a pict of a lightsaber.
The only required argument is a color, which can be either a color
name or a color% object. A length can be provided as an optional
argument, as well as a style for the lightsaber hilt. The default hilt
is Luke Skywalker's (#:style 'luke), but you can also select Darth
Vader's (#:style 'vader), Kylo Ren's (#:style 'kylo), or Darth Maul's
(#:style 'maul). See the attached picture for examples of each.

The code is available at https://github.com/zamora/lightsaber

Thanks to Stephen De Gabrielle for providing the incentive to learn
about pict and have some fun!

Justin

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CA%2B80D0Xhbq8VTvNLL3CsA6zgQEXmj8uWzY_JzzRVZNboMVaYbg%40mail.gmail.com.


Re: [racket-users] The case, and a proposal, for elegant syntax in #lang racket2

2019-07-18 Thread Justin Zamora
On Thu, Jul 18, 2019 at 1:48 PM Brian Adkins  wrote:
> I think more people (both existing users and new users) could get
> excited about Racket2 if it was primarily about making Racket
> objectively better and only secondarily about overcoming the
> aesthetic objection to parens. The message of "After years of effort,
> now you can program in Racket without using so many parens!" does not
> seem compelling to me.

The discussions about changing syntax are not about aesthetics. There are some
genuine pain points in Racket that could be fixed with alternate
syntax. For instance,
it's easy for structure and array access to become unwieldy in
practice. Even a simple
example can show how awkward it can be. Suppose you have:

(struct person (first middle last))
(define john (person "John" "Allen" "Smith"))

Now you want the person's initials. In Racket, the code is:

(string (string-ref (person-first john) 0)
(string-ref (person-middle john) 0)
(string-ref (person-last john) 0))

There's a load of cognitive and syntactic overhead compared to something like:

john.first[0] + john.middle[0] + john.last[0]

Even as someone who has programmed in Scheme for 30 years, I have to spend
a couple seconds to grasp what the Racket code is doing, while the alternative
syntax is almost instantly understandable.

Making changes to eliminate such pain points may help new users to
consider Racket,
but even if they don't, there is still plenty of benefit to existing
Racket programmers.

Justin

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CA%2B80D0UStMcFACb1mS%2BR%3D6GNH_9s1uubrgi1S4HCh%2BZKEf%2BF6A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] color-maps for the plot package

2019-03-19 Thread Justin Zamora
On Tue, Mar 19, 2019 at 10:35 PM Ben Greenman
 wrote:
> I'm thinking a color-map% object would define a possibly-infinite
> sequence of colors that look nice in some way. The colors might be
> useful anywhere where someone wants a "rainbow" of colors ... maybe
> for:

If you're interested in contrasting colors instead of a gradient, you
could use philogenic colors, the way Pyret does for its error
messages. http://blog.brownplt.org/2018/06/11/philogenic-colors.html

Justin

-- 
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: Types of languages Re: [racket-users] the list of languages made with racket [Hacker News]

2019-03-01 Thread Justin Zamora
You should include Danny Yoo's Brainfudge in the "stand-alone
languages with non-s-exp syntax".
https://www.hashcollision.org/brainfudge/index.html

Justin

On Fri, Mar 1, 2019 at 6:15 PM Stephen De Gabrielle
 wrote:
>
>
>
> On Fri, 1 Mar 2019 at 18:00, Matthias Felleisen  
> wrote:
>>
>>
>>
>> > On Mar 1, 2019, at 12:05 PM, Stephen De Gabrielle 
>> >  wrote:
>> >
>> > Hi Matthias,
>> > (or anyone else who is available to answer :))
>> >
>> > I'm trying to get my head around the range of possible languages in Racket.
>> >
>> > You got me thinking how many languages seem to have embedded little 
>> > languages.
>> > I was wondering how they fit into your categories of languages?
>> >
>> > 3. The nature of languages ranges from
>> > — stand-alone languages with ugly syntax (example: datalog)
>> > — #lang stand-alone DSLs (config, scribble)
>> >
>> > Does '#lang video' fit in this group?
>>
>> Yes.
>>
>>
>> >
>> > — #lang language mixins (s-expr, 2d)
>> >
>> > Do regular #px""/#rx expressions fit in this category?
>>
>> I don’t understand how #px is similar to the s-expr or at-expr or 2d #lang 
>> mixins. I am referring to lines such as #lang at-exp scribble.
>>
>> [...]
>> p.s. In my mind, format and regexp-match (and similar functions) are 
>> interpreters for programs in DSLs that are written down as strings. That’s 
>> my opening slides for HtDL (from last year).
>
>
> The example from Greg Hendershot, below, gave the impression they were like 
> at-exp and the #2dcond syntax extension seems to fit the same pattern as #px 
> , but I see what you mean about regex-match and format being interpreters.
> @pregexp{\d\.\d}  ; #px"\\d\\.\\d"  (from 
> https://www.greghendershott.com/2015/08/at-expressions.html )
> (I do use that trick to make regexp more readable - at-exp is great)
>
> leaving aside my confusion, my goal here is to a page to the racket website 
> that showcases an selection of languages made with Racket, that is better 
> than a search of things that define a #lang
>
> #lang stand-alone languages with non-s-exp syntax (I'm inclined not to 
> include 'ugly syntax' on a PR for the racket website)
>
> Algol 60
> Datalog
> Scratchy
> ProfessorJ (deliberately included as ~30% of job ads in the UK specify Java)
> Rash: The Reckless Racket Shell
> Riposte
>
> #lang stand-alone DSLs (config?, scribble)
>
> (I don't know a 'config' lang apart from #lang info)
>
> Scribble
> Hackett
> Heresy
> Lindenmayer
> Parenlog
> Pie
> Video
>
>
> #lang language mixins (s-expr, 2d)
>
> #lang s-exp [module]
> #lang 2d racket
> #lang at-exp
>
> embedded DSLs with mostly coarse-grained interactions with Racket (redex)
>
> Redex (require redex)
> [need to identify another example]
>
>
> embedded DSLs with fine-grained interaction with Racket (the language of 
> class syntax; syntax-parse: the pattern and templated languages, which 
> interact via syn-pattern vars)
>
> (require racket/class)
> syntax-parse
> syntax-case patterns and templates etc.
>
>
> string interpreters
>
> regexp
> format
>
>
> Languages with other targets
>
> Asi64
> Pollen
> Scribble (?)
> Racket-script
>
>
> Are these good categories?
>
> Kind regards,
>
> Stephen
>
> --
> 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] Re: How To Design Classes text not available?

2019-02-02 Thread Justin Zamora
Thanks! I always forget about archive.org!

Justin

On Sat, Feb 2, 2019 at 3:29 PM Greg Trzeciak  wrote:
>
> Try
>
> https://web.archive.org/web/20181228174204/http://www.ccs.neu.edu/home/matthias/HtDC/htdc.pdf
>
> On Saturday, February 2, 2019 at 9:26:15 PM UTC+1, Justin Zamora wrote:
>>
>> I tried to download the draft of "How to Design Classes" from
>> http://www.ccs.neu.edu/home/matthias/htdc.html and got a "Failed to
>> load PDF document" error. Is this text still available?
>>
>> Justin
>
> --
> 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] How To Design Classes text not available?

2019-02-02 Thread Justin Zamora
I tried to download the draft of "How to Design Classes" from
http://www.ccs.neu.edu/home/matthias/htdc.html and got a "Failed to
load PDF document" error. Is this text still available?

Justin

-- 
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] Byte Order Mark: alter display of symbols containing nonprinting characters?

2017-12-27 Thread Justin Zamora
There are many characters that have different Unicode values but use the
same glyphs. Many Cyrillic characters look like their English characters,
so they appear the same visually, but equal? and eq? reveal that they are
actually distinct. It seems to be that the BOM is just another example on
this sort of thing, and people will need to learn that they can't
necessarily trust their eyes.

#lang racket

(define cyrillic (string->symbol "\u0410\u0412\u0421"))
(define english (string->symbol "ABC"))
cyrillic
english
(equal? cyrillic english)
(eq? cyrillic english)

Welcome to DrRacket, version 6.9 [3m].
Language: racket, with debugging; memory limit: 128 MB.
'АВС
'ABC
#f
#f
>

Justin

On Wed, Dec 27, 2017 at 10:33 PM, Jay McCarthy 
wrote:

> Okay. I think I understand.
>
> The behavior of "two things print the same but are actually different"
> that Racket has seems to be the same as my editor and Web browser
> which don't render the BOM as anything unless I fiddle something in
> Emacs. Additionally, it seems painful to make it do it a different
> way.
>
> On Wed, Dec 27, 2017 at 10:26 PM, John Clements
>  wrote:
> >
> >
> >> On Dec 27, 2017, at 19:06, Jay McCarthy  wrote:
> >>
> >> This seems to be consistent with my Web browser and editor. Are the
> >> symbols eq? or equal?
> >
> > Neither. Am I misunderstanding you? Here’s code:
> >
> > #lang racket
> >
> > (define bad-symbol (string->symbol "\uFEFFhello"))
> >
> > (define regular-symbol 'hello)
> >
> > bad-symbol
> > regular-symbol
> > (equal? bad-symbol regular-symbol)
> > (eq? bad-symbol regular-symbol)
> >
> > this evaluates in DrR to:
> >
> > Welcome to DrRacket, version 6.11.0.5--2017-12-20(-/f) [3m].
> > Language: racket, with debugging; memory limit: 4096 MB.
> > 'hello
> > 'hello
> > #f
> > #f
> >>
> >
> > If you copy and paste these from the interactions into the definitions
> window, you can even get this:
> >
> > #lang racket
> >
> > (equal? 'hello 'hello)
> > (eq? 'hello ‘hello)
> >
> > evaluates to:
> >
> > Welcome to DrRacket, version 6.11.0.5--2017-12-20(-/f) [3m].
> > Language: racket, with debugging; memory limit: 4096 MB.
> > #f
> > #f
> >>
> >
> > Did you misunderstand me, or did I misunderstand you?
> >
> > John
> >
> >
> >
> >
> >
> >>
> >
> >> On Wed, Dec 27, 2017 at 3:54 PM, 'John Clements' via Racket Users
> >>  wrote:
> >>> I was working with files containing a Byte Order Mark today, and in
> the process of writing a test case, I discovered that
> >>>
> >>> (string->symbol “\uFEFF”)
> >>>
> >>> produces a symbol whose printed representation is
> >>>
> >>> ‘hello
> >>>
> >>> … which seems unfortunate; I guess I would have expected something like
> >>>
> >>> ‘|\uFEFFhello|
> >>>
> >>> (… although I see now that this kind of escaping is not currently
> enabled inside vertical bars).
> >>>
> >>> This leads to situations where two symbols with the same printed
> representation may not be equal?, which seems unfortunate.
> >>>
> >>> Am I overlooking a good reason why this is the desired behavior?
> >>>
> >>> John
> >>>
> >>>
> >>>
> >>> --
> >>> 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.
> >>
> >>
> >>
> >> --
> >> -=[ Jay McCarthy   http://jeapostrophe.github.io]=-
> >> -=[ Associate ProfessorPLT @ CS @ UMass Lowell ]=-
> >> -=[ Moses 1:33: And worlds without number have I created; ]=-
> >>
> >> --
> >> 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.
> >
> >
> >
>
>
>
> --
> -=[ Jay McCarthy   http://jeapostrophe.github.io]=-
> -=[ Associate ProfessorPLT @ CS @ UMass Lowell ]=-
> -=[ Moses 1:33: And worlds without number have I created; ]=-
>
> --
> 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] Re: Proper non-tail recursion?

2017-04-27 Thread Justin Zamora
On Thu, Apr 27, 2017 at 8:06 PM, Jon Zeppieri  wrote:
>
> OCaml does handle tail calls properly. But proper tails calls are not
> the subject of this discussion. The original post was explicitly about
> non-tail calls and how, in Racket, you cannot exhaust the stack
> without exhausting all of the memory available to the program.
> (Whereas in OCaml you can, because it uses a fixed-size stack.)
>

How common is it to have a fixed-size stack? I thought it was normal
practice for the heap and stack to be on opposite ends of memory and to
grow towards each other, so that either can use all available memory.

Justin

-- 
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] Recursevly processing a list with "wholes"

2016-11-16 Thread Justin Zamora
I think you are looking for something like this:

#lang racket

(require test-engine/racket-tests)

(define (remove-empty-lists lst)
  (cond
[(null? lst) '()] ; Check for end of list
[(null? (first lst)) (remove-empty-lists (rest lst))] ; Skip null
sublist
[(not (list? (first lst))) ; Leave non-lists alone
 (cons (first lst) (remove-empty-lists (rest lst)))]
[else ; Process the sublists recursively
 (cons (remove-empty-lists (first lst))
   (remove-empty-lists (rest lst)))]))

(check-expect (remove-empty-lists '()) '())
(check-expect (remove-empty-lists '(a)) '(a))
(check-expect (remove-empty-lists '(a b c)) '(a b c))
(check-expect (remove-empty-lists '(())) '())
(check-expect (remove-empty-lists '(() a)) '(a))
(check-expect (remove-empty-lists '(a ())) '(a))
(check-expect (remove-empty-lists '(a (b () c) d)) '(a (b c) d))
(check-expect (remove-empty-lists '((a) (b c) () (e () f (g ())) h (() i
j)))
  '((a) (b c) (e f (g)) h (i j)))
(test)

Justin

On Tue, Nov 15, 2016 at 10:52 PM,  wrote:

> Hi,
>
> I have a list of sublists. Some of the sublists are empty.
> The list should be processed recursevly and the resulting
> list should no longer contain empty sublists.
>
> The code I have so far looks like:
>
> (define (step-through-list lst)
> (if (empty? lst)
> lst
> (cons (process-sublist (car lst)) (step-through-list (cdr lst)))
>
> but "car" would feed empty sublists to process-sublist as any other
> sublist. How can I "silently" skip empty sublists and even get out of
> the recursion without harm (if the last sublist is empty) without
> switching to iteration?
> Is there something like "car-not-empty" ? ;)
> Or do I oversee the obvious here...? ;)))
>
> Thank you vary much for any help in advance!
> Cheers
> Meino
>
>
> --
> 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] Funtional programming and the maximum of something

2016-10-22 Thread Justin Zamora
A clue to the answer is in your statement that you "feed that [maximum]
into the next circle of recursion." Notice that you're not overwriting the
value in the current call, you're creating a new value that you feed into
the new call in the "next circle". So the old one isn't being overwritten
at all.

Justin

On Oct 22, 2016 3:15 PM,  wrote:

> Hi,
>
> (I am still a newbie ... )
>
> If I remember  one rule of functional programming
> correctly, it says:
> Instead of changeing data - create new data.
>
> Suppose I have a list of list. Each "sublist" is
> made of a greater amount (but identical count) of
> exact numbers (integers).
>
> I want to process these data recursively and if
> all is done I want to get back a list of numbers
> (same count of numbers as in each sublist), which
> represents the maximum of all numbers of that "position"
> in all sublists.
>
> If I want to make this purely (may be inpractical) functional,..
> I see (as a newbie) the following problem.
> From two numbers as input I have to build a maximum and
> have to feed that into the next circle of recursion as
> one of the numbers to compare.
> Each time a new maximum is found I have to overwrite the
> old one.
> This contradicts the rule "Dont change data, create new one."
>
> How can I get out of this?
>
> Cheers
> Meino
>
>
>
>
> --
> 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] Help writing a simple lexer/tokenizer

2016-02-22 Thread Justin Zamora
You can also try using a state machine using the approach described in
https://cs.brown.edu/~sk/Publications/Papers/Published/sk-automata-macros/paper.pdf
On Feb 22, 2016 4:46 PM, "Federico Ramírez"  wrote:

> Hello everyone! I'm new to Scheme, and I need some help wrapping my head
> around it.
>
> I want to write a simple tokenizer, which is just a function that takes a
> string as input and outputs a list of "tokens", which to keep thing simple
> is a tuple of NAME and VALUE.
>
> So, for example:
>
> (tokenize "foo = 1") => '((IDENTIFIER . "foo") (EQUALS . "=") (NUMBER . 1))
>
> I didn't want to use global variables to keep things functional, so my
> solution doesn't use any, but I wouldn't mind much using them. This is some
> code for my current implementation, I omit some code for brevity as it's
> quite repetitive for now:
>
> (define (match-identifier input)
>   (regexp-match #rx"^[a-zA-Z_]+"))
>
> (define (consume-identifier input)
>   (let ([match (first (match-identifier input))])
> (cons `(IDENTIFIER . ,match) (tokenize (substring input (string-
>   length match))
>
> ;; some more matchers and consumers, all pretty similar
> ;; ...
>
> (define (tokenize input)
>   (cond
> ((match-identifier input) (consume-identifier input))
> ((match-equals input) (consume-equals input))
> ((match-number input) (consume-number input))
> (else '(
>
> What bothers me is that it's calling the matchers twice for each token,
> which isn't very good for performance and it's not pretty :p
>
> I want to get rid of that double-check. I figured I could use some globals
> in order to do it but I'd rather not.
>
> Does anyone have a suggestion/fix on my implementation?
>
> Thank you for your time :)
>
> --
> 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] PSA for DrRacket users who like Emacs keybindings

2016-02-01 Thread Justin Zamora
The sequence C-a C-x C-s does something very different when Emacs
keybindings are not active. :(

Justin

-- 
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] Applying functions to mutable lists

2015-04-09 Thread Justin Zamora
Why not use streams? http://docs.racket-lang.org/reference/streams.html

Justin
On Apr 9, 2015 11:22 AM, Jerry Jackson jrryjc...@gmail.com wrote:

 Hello,

 I'm building a language with racket that includes lazy lists. I'm building
 lazy lists with mcons cells. The compatibility/mlist module has lots of
 support functions but I'd like to be able to apply racket functions to the
 lists I've constructed and I don't see any mapply. I understand that the
 use of mutable cons cells is discouraged but I don't currently know of a
 better way to do lazy lists. If there is a different recommended way, I'd
 like to know about it. If not:

 1) Is there an equivalent of mapply that I just haven't found or
 2) Is there a reason it's a really bad idea or
 3) Was it just left out because nobody so far needed it?

 Thanks for any help,

 --Jerry Jackson

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