Re: [racket-users] Case vs. Match
Really this is not the best example either. I guess best to look at the source, which is in racket/private/case and, according to a comment in the top of the file, is based on Clinger's paper, "Rapid Case Dispatch in Scheme". Robby On Fri, Jun 3, 2016 at 6:35 PM, Robby Findlerwrote: > I think they need to be bigger, but case does have some smarts. Try > this one (add a `pretty-write` if you're running in cmd-line racket). > > #lang racket > (syntax->datum > (expand > #'(case x > [(1 2 3 4 5 6 7 8 9 10) 1] > [(a b c d e f g h i j k l m n o p q r s t) 2]))) > > > On Fri, Jun 3, 2016 at 6:23 PM, Gustavo Massaccesi wrote: >> > [...] I saw in the docs that case specifically mentions it can >> distribute in log(n) time [...] >> >> I think it's strange. I found the reference in >> https://docs.racket-lang.org/reference/case.html but it's very >> strange. Is it true??? >> >> For example, I tried with >> >> ;--- >> #lang racket >> (lambda (x) >> (case x >> [(1 "1" #"1" |1|) 1] >> [(2 "2" #"2" |2|) 2])) >> (lambda (x) >> (case x >> [(1 3 5 7) 1] >> [(2 4 6 8) 2])) >> ;--- >> >> but both expand to a bunch of nested if, nothing fancy that may run in >> O(log(N)). >> (I don't expect that it has a smarter implementation for bigger N.) >> >> Gustavo >> >> >> On Fri, Jun 3, 2016 at 11:40 AM, Gerald Pipes >> wrote: >>> On Friday, June 3, 2016 at 10:30:35 AM UTC-4, Jon Zeppieri wrote: There's rarely a good reason. If you were dispatching over a very large set of constants -- fixnums or characters, in particular -- I'd expect better performance from case. That's about it. > On Jun 3, 2016, at 10:10 AM, Gerald Pipes > wrote: > > I have been recently using match a lot and I was wondering what was the > main benefit of using case instead of match? It seems as though match > has the distribution on a single val-exp except match allows for the > pattern matching and case just uses equal?. > > -- > 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. >>> >>> Yes, I saw in the docs that case specifically mentions it can distribute in >>> log(n) time but for match there is no time mentioned. I assumed case's >>> performance was better because of the performance omission of match. Does >>> anyone know the actual performance of match? >>> >>> -- >>> 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. -- 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] Case vs. Match
I think they need to be bigger, but case does have some smarts. Try this one (add a `pretty-write` if you're running in cmd-line racket). #lang racket (syntax->datum (expand #'(case x [(1 2 3 4 5 6 7 8 9 10) 1] [(a b c d e f g h i j k l m n o p q r s t) 2]))) On Fri, Jun 3, 2016 at 6:23 PM, Gustavo Massaccesiwrote: > > [...] I saw in the docs that case specifically mentions it can > distribute in log(n) time [...] > > I think it's strange. I found the reference in > https://docs.racket-lang.org/reference/case.html but it's very > strange. Is it true??? > > For example, I tried with > > ;--- > #lang racket > (lambda (x) > (case x > [(1 "1" #"1" |1|) 1] > [(2 "2" #"2" |2|) 2])) > (lambda (x) > (case x > [(1 3 5 7) 1] > [(2 4 6 8) 2])) > ;--- > > but both expand to a bunch of nested if, nothing fancy that may run in > O(log(N)). > (I don't expect that it has a smarter implementation for bigger N.) > > Gustavo > > > On Fri, Jun 3, 2016 at 11:40 AM, Gerald Pipes > wrote: >> On Friday, June 3, 2016 at 10:30:35 AM UTC-4, Jon Zeppieri wrote: >>> There's rarely a good reason. If you were dispatching over a very large set >>> of constants -- fixnums or characters, in particular -- I'd expect better >>> performance from case. That's about it. >>> >>> > On Jun 3, 2016, at 10:10 AM, Gerald Pipes >>> > wrote: >>> > >>> > I have been recently using match a lot and I was wondering what was the >>> > main benefit of using case instead of match? It seems as though match >>> > has the distribution on a single val-exp except match allows for the >>> > pattern matching and case just uses equal?. >>> > >>> > -- >>> > 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. >> >> Yes, I saw in the docs that case specifically mentions it can distribute in >> log(n) time but for match there is no time mentioned. I assumed case's >> performance was better because of the performance omission of match. Does >> anyone know the actual performance of match? >> >> -- >> 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. -- 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] Case vs. Match
On Sat, Jun 4, 2016 at 1:23 AM, Gustavo Massaccesiwrote: > > [...] I saw in the docs that case specifically mentions it can > distribute in log(n) time [...] > but both expand to a bunch of nested if, nothing fancy that may run in > O(log(N)). > (I don't expect that it has a smarter implementation for bigger N.) It indeed has some smarts. Try expanding the following: #lang racket (lambda (x) (case x ((1) 1) ((2) 1) ((3) 1) ((4) 1) ((5) 1) ((6) 1) ((7) 1) ((8) 1) ((9) 1) ((10) 1) ((11) 1) ((12) 1) ((13) 1) ((14) 1) ((15) 1) ((16) 1) ((17) 1) ((18) 1) ((19) 1) ((20) 1) )) -- 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] Case vs. Match
> [...] I saw in the docs that case specifically mentions it can distribute in log(n) time [...] I think it's strange. I found the reference in https://docs.racket-lang.org/reference/case.html but it's very strange. Is it true??? For example, I tried with ;--- #lang racket (lambda (x) (case x [(1 "1" #"1" |1|) 1] [(2 "2" #"2" |2|) 2])) (lambda (x) (case x [(1 3 5 7) 1] [(2 4 6 8) 2])) ;--- but both expand to a bunch of nested if, nothing fancy that may run in O(log(N)). (I don't expect that it has a smarter implementation for bigger N.) Gustavo On Fri, Jun 3, 2016 at 11:40 AM, Gerald Pipeswrote: > On Friday, June 3, 2016 at 10:30:35 AM UTC-4, Jon Zeppieri wrote: >> There's rarely a good reason. If you were dispatching over a very large set >> of constants -- fixnums or characters, in particular -- I'd expect better >> performance from case. That's about it. >> >> > On Jun 3, 2016, at 10:10 AM, Gerald Pipes >> > wrote: >> > >> > I have been recently using match a lot and I was wondering what was the >> > main benefit of using case instead of match? It seems as though match has >> > the distribution on a single val-exp except match allows for the pattern >> > matching and case just uses equal?. >> > >> > -- >> > 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. > > Yes, I saw in the docs that case specifically mentions it can distribute in > log(n) time but for match there is no time mentioned. I assumed case's > performance was better because of the performance omission of match. Does > anyone know the actual performance of match? > > -- > 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] Case vs. Match
On Friday, June 3, 2016 at 10:30:35 AM UTC-4, Jon Zeppieri wrote: > There's rarely a good reason. If you were dispatching over a very large set > of constants -- fixnums or characters, in particular -- I'd expect better > performance from case. That's about it. > > > On Jun 3, 2016, at 10:10 AM, Gerald Pipes> > wrote: > > > > I have been recently using match a lot and I was wondering what was the > > main benefit of using case instead of match? It seems as though match has > > the distribution on a single val-exp except match allows for the pattern > > matching and case just uses equal?. > > > > -- > > 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. Yes, I saw in the docs that case specifically mentions it can distribute in log(n) time but for match there is no time mentioned. I assumed case's performance was better because of the performance omission of match. Does anyone know the actual performance of match? -- 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] Case vs. Match
There's rarely a good reason. If you were dispatching over a very large set of constants -- fixnums or characters, in particular -- I'd expect better performance from case. That's about it. > On Jun 3, 2016, at 10:10 AM, Gerald Pipes> wrote: > > I have been recently using match a lot and I was wondering what was the main > benefit of using case instead of match? It seems as though match has the > distribution on a single val-exp except match allows for the pattern matching > and case just uses equal?. > > -- > 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] Case vs. Match
match is far more expressive than case. Think of > (match 3 [(? even? x) (+ x 1)][(? odd? x) (- x 1)]) But of course you’re paying for in terms of run-time cost. Engineering is a trade-off game. > On Jun 3, 2016, at 10:10 AM, Gerald Pipes> wrote: > > I have been recently using match a lot and I was wondering what was the main > benefit of using case instead of match? It seems as though match has the > distribution on a single val-exp except match allows for the pattern matching > and case just uses equal?. > > -- > 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] Case vs. Match
I have been recently using match a lot and I was wondering what was the main benefit of using case instead of match? It seems as though match has the distribution on a single val-exp except match allows for the pattern matching and case just uses equal?. -- 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] auto-defining variables mentioned in a program
On Jun 2, 2016, at 11:47 AM, Jack Firthwrote: > - Have #%top somehow magically figure out if it should make a new box or > reuse an existing one for the identifier it's given. (call-with-future-miracle ...) I'll think about it more — but my hunch is this problem is more related to parsing the program into an AST, not macro expansion per se. (Moreover, it's easy for me to see how certain adjustments to the parser grammar can make the variable names easier to find & extract; harder to see how to do the same with the expander.) -- 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.