Re: [racket-users] existing predicate for membership in TR Sexp type?
> On Sep 25, 2017, at 5:52 AM, Matthias Felleisen wrote: > > >> On Sep 24, 2017, at 9:32 PM, 'John Clements' via users-redirect >> wrote: >> >> Now that I know how much faster ‘assert’ can be than ‘cast’, I’m eager to >> replace uses of ‘assert' all over the place. >> >> Specifically, in my PL class, I’m hoping to get rid of uses of (cast … Sexp) >> that wind up principally in RHSes of match clauses. >> >> In order to do this, I need a predicate of type (-> Any Boolean : Sexp). >> >> Well, strictly speaking, all I really need is the positive half, which I can >> construct like this: >> >> (: sexp? (-> Any Boolean : #:+ Sexp)) >> (define (sexp? s) >> (or (number? s) >> (symbol? s) >> (string? s) >> (and (pair? s) (sexp? (car s)) (sexp? (cdr s))) >> (null? s))) >> >> This works fine, and I can use it in an assert. >> >> Should I just drop this on my students, or is there an existing s-expression >> checking predicate that I can use? >> >> Apologies if I’m just not looking hard enough! > > > The definition of S-expression tends to be parameterized over the leafs > (atoms). I’d be surprised if your particular version existed. [I assume you > understand that you’re handing them a parser and that the use of this > predicate may slow down the function (in terms of O-class).] — Matthias For this class, it’s all about ‘match’; last year, TR’s treatment of `match` wasn’t clever enough in many instances to deduce that a particular pattern variable’s value inhabits, say, Sexp, requiring either a cast or an assert. It may be that this year, TR is sufficiently sophisticated in its handling of `match` to obviate this need. If not, though, I’ll need either a cast or an assert. (If I’m thinking about this problem correctly, then *either* a cast or an assert is going to boost the asymptotic running time; even if TR can perform deduplication of casts to the same type, I think this still incurs the same asymptotic penalty.) Thanks! 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.
Re: [racket-users] existing predicate for membership in TR Sexp type?
> On Sep 24, 2017, at 9:32 PM, 'John Clements' via users-redirect > wrote: > > Now that I know how much faster ‘assert’ can be than ‘cast’, I’m eager to > replace uses of ‘assert' all over the place. > > Specifically, in my PL class, I’m hoping to get rid of uses of (cast … Sexp) > that wind up principally in RHSes of match clauses. > > In order to do this, I need a predicate of type (-> Any Boolean : Sexp). > > Well, strictly speaking, all I really need is the positive half, which I can > construct like this: > > (: sexp? (-> Any Boolean : #:+ Sexp)) > (define (sexp? s) > (or (number? s) > (symbol? s) > (string? s) > (and (pair? s) (sexp? (car s)) (sexp? (cdr s))) > (null? s))) > > This works fine, and I can use it in an assert. > > Should I just drop this on my students, or is there an existing s-expression > checking predicate that I can use? > > Apologies if I’m just not looking hard enough! The definition of S-expression tends to be parameterized over the leafs (atoms). I’d be surprised if your particular version existed. [I assume you understand that you’re handing them a parser and that the use of this predicate may slow down the function (in terms of O-class).] — Matthias -- 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] existing predicate for membership in TR Sexp type?
Now that I know how much faster ‘assert’ can be than ‘cast’, I’m eager to replace uses of ‘assert' all over the place. Specifically, in my PL class, I’m hoping to get rid of uses of (cast … Sexp) that wind up principally in RHSes of match clauses. In order to do this, I need a predicate of type (-> Any Boolean : Sexp). Well, strictly speaking, all I really need is the positive half, which I can construct like this: (: sexp? (-> Any Boolean : #:+ Sexp)) (define (sexp? s) (or (number? s) (symbol? s) (string? s) (and (pair? s) (sexp? (car s)) (sexp? (cdr s))) (null? s))) This works fine, and I can use it in an assert. Should I just drop this on my students, or is there an existing s-expression checking predicate that I can use? Apologies if I’m just not looking hard enough! 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.