Re: [racket-users] [macro help] How can I render a parenthesized set of elements optional?

2019-02-15 Thread Alexis King
Jon is right. Here’s an explanation why.

Think of `...` as a postfix operator. It repeats what comes before it a certain 
number of times. In order for `...` to know how many times to repeat the 
previous head template, it looks inside the head template for any attributes 
bound at the appropriate ellipsis depth, and it repeats the head template once 
for each value of the attributes. The `...` operator essentially creates a 
loop, iterating through each value of the attribute.

The value of attributes bound under ellipses are therefore lists. You can see 
this for yourself if you use the `attribute` accessor to explicitly get at the 
value of an attribute matched under an ellipsis:

  > (syntax-parse #'(a b c)
  [(x:id ...)
   (attribute x)])
  '(#
#
#)

But what happens to the value of an attribute when it is completely 
unspecified, since it has been marked `~optional`? If the `~optional` wraps the 
whole sequence, such that the ellipsis is inside the `~optional` pattern, then 
the attribute is not a list at all, but `#f`:

  > (syntax-parse #'()
  [({~optional (x:id ...)})
   (attribute x)])
  #f

This causes problems. If we were to write #'(x ...) when `x` is bound to `#f`, 
then the template will raise an error, since `x` isn’t a list, and therefore 
the ellipses don’t know how many times to repeat the preceding template.

What you tried to do is silence that error by wrapping the offending template 
with `~?`. This is a natural thing to try, but it doesn’t work. Why? Well, it’s 
true that {~? x} turns into {~@} when `x` is `#f`, but this does not matter, 
since you essentially wrote ({~? x} ...). This means that the `x` under the 
ellipsis doesn’t refer to the attribute `x` as a whole, but instead refers to 
each *element* of `x`, since `...` creates a loop. So the template attempts to 
iterate through the values of (attribute x), but it finds that value isn’t a 
list at all, gets confused, and explodes.

Jon’s fix changes this. It moves the looping *inside* the `~?`, which means 
that `~?` is now looking at `x` as a whole (not each element of `x`), and just 
skips the loop altogether, avoiding the error. It’s morally the difference 
between this code:

  (for/list ([x (in-list (attribute x))])
(if x x #'{~@}))

and this code:

  (if (attribute x)
  (for/list ([x (in-list (attribute x))])
x)
  #'{~@})

---

A secondary question: is the template #'({~? x} ...) ever useful? And the 
answer is: YES! It just does something different.

Since #'({~? x} ...) iterates through the values of `x` before checking for 
`#f`-ness, then it is useful when `x` itself is never `#f`, but elements of it 
may be. This can appear when parsing, say, a list of pairs, where the second 
element of each pair is optional:

  > (define parse-pairs
  (syntax-parser
[([x:id {~optional n:nat}] ...)
 #'([x ...]
[{~? n} ...])]))
  > (parse-pairs #'([a 1] [b] [c 3]))
  #
  > (parse-pairs #'([a] [b] [c]))
  #

Note that when there are no numbers in the input, the output list is still 
present but is simply empty, while when some but not all numbers are provided, 
the missing numbers are simply skipped in the output.

---

One final point: you may think to yourself “all of this is confusing and 
procedural, why should I have to think about attributes?” While I think 
understanding what’s going on internally can be helpful, it isn’t strictly 
necessary. There’s actually a declarative intuition to guide whether you should 
write #'({~? {~@ x ...}}) or #'({~? x} ...). This intuition is as follows.

There is a dualism in `syntax-parse`’s pattern language and in the `syntax` 
form’s template language. For example:

  - Writing `x` in a pattern, where `x` is an identifier, matches a term, and 
writing `x` in a template constructs the same term.

  - Writing (a . b) in a pattern matches a pair, and writing (a . b) in a 
template constructs a pair.

  - Writing `p ...` in a pattern matches zero or more occurrences of the 
pattern `p`, and writing `t ...` in a template that contains variables bound in 
`p` constructs the same number of occurrences in the template.

To put things another way:

  - Variables in patterns correspond to variables in templates.
  - (a . b) in patterns corresponds to (a . b) in templates.
  - `...` in patterns corresponds to `...` in templates.

This might seem obvious, but it turns out that `~?` and `~@` have cousins in 
the pattern language, too. They are just less obvious, because their cousins 
have different names:

  - `~optional` in patterns corresponds to `~?` in templates.
  - `~seq` in patterns corresponds to `~@` in templates.

(I would have liked `~?` and `~@` to be named `~optional` and `~seq` to make 
this duality clearer, but sadly, since `~?` and `~@` were added recently, 
reusing existing names would make them backwards incompatible with older code 
that expanded to `syntax-parse` patterns.)

Since `~optional` corresponds to 

[racket-users] [ANN] scribble/minted, code highlighting via pygmentize

2019-02-15 Thread William J. Bowman
In case anyone else needs this and wasn't looking at that other thread with an
unrelated subject:

I made a little scribble library to do code highlighting through pygmentize in a
way that supports multiple backend renderers.
  https://github.com/wilbowma/scribble-minted

Supports PDF, LaTeX, and HTML renderers.
(Probably not hard to make it support text and markdown, but I don't really need
those right now.)

It's probably a bit fragile.

-- 
William J. Bowman

-- 
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 document extending a renderer with a new mixin

2019-02-15 Thread William J. Bowman
I was missing something: a bug in my code.

FYI, I got this working if anyone wants an example of how to patch Scribble's
current render mixin.

https://github.com/wilbowma/scribble-minted

--
William J. Bowman

On Fri, Feb 15, 2019 at 05:48:37PM -0800, William J. Bowman wrote:
> I've created a scribble render mixin to call out to pygmentize for typesetting
> certain code elements with a certain style.
> However, it seems to me that I can't get scribble to use the mixin without
> modifying scribble/run.rkt.
> I've tried (via rackunit's require/expose) modifying current-render-mixin 
> (which
> was a bad idea that wasn't likely to work), and it didn't work.
> 
> Am I missing something or should I try to make a patch to that enables 
> scribble
> to load a mixin from a given document?
> 
> -- 
> William J. Bowman
> 
> -- 
> 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] [macro help] How can I render a parenthesized set of elements optional?

2019-02-15 Thread Jon Zeppieri
On Fri, Feb 15, 2019 at 11:50 PM David Storrs 
wrote:

>
> #lang racket
> (require (for-syntax racket/syntax syntax/parse))
>
> (define-syntax (struct++ stx)
>   (syntax-parse stx
> [(_ name:id (field:id ...) (~optional (rule:expr ...)) opt ...)
>  #'(begin (struct name (field ...) opt ...)
> (list (~? rule) ... ))]))
>
>
I think this does what you want:
   (list (~? (~@ rule ...)))

-- 
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] Running raco setup from within DrRacket?

2019-02-15 Thread jackhfirth
Using setup/setup works partially, but it doesn't seem to support package 
dependency checking (and the #:pkgs keyword argument isn't documented). I 
can't seem to find any programmatic alternative to the --check-pkg-deps and 
--unused-pkg-deps flags.

On Friday, February 15, 2019 at 8:35:17 PM UTC-8, Matthias Felleisen wrote:
>
> See 
> https://docs.racket-lang.org/raco/setup-plt-plt.html?q=setup#%28def._%28%28lib._setup%2Fsetup..rkt%29._setup%29%29
>  
>
> (require setup/setup) 
>
> I think that’s what you want — 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] [macro help] How can I render a parenthesized set of elements optional?

2019-02-15 Thread David Storrs
I'm twiddling with struct-plus-plus, adding declarative rules, and ~?
isn't doing what I expect. I expect that:

(~? rule) ...

is equivalent to (~? rule (~@)) and means "If `rule` matched
something, insert it here.  Do this for each item that `rule` matched.
If `rule` did not match anything, put nothing here."  That's not what
I'm seeing, though.  The following is as stripped-down as I can get it
and still demonstrate the problem.

#lang racket
(require (for-syntax racket/syntax syntax/parse))

(define-syntax (struct++ stx)
  (syntax-parse stx
[(_ name:id (field:id ...) (~optional (rule:expr ...)) opt ...)
 #'(begin (struct name (field ...) opt ...)
(list (~? rule) ... ))]))

Given this declaration, it should be legal to omit the second set of
parentheses and their contents, but I'm getting compilation errors
when I do that.

; This works fine
(struct++ animal (species) ('testing 'testing) #:transparent)
(animal 'dog)

; As does this
(struct++ person (name age) ()  #:transparent)
(person 'bob 19)

; The lack of the second set of parens causes
; compilation to fail with the error:
;  ?: attribute contains non-list value
;  value: #f
(struct++ person (name age) #:transparent)
(person 'bob 19)

I can analyze it this far:  I'm using the (~? head-template) form
here.  `rule` is an identifier bound to a pattern variable, so `rule`
is a template.  All templates are head-templates, therefore `rule` is
a head template.  There were no rules for `rule` to match so `rule`
should be a missing pattern variable within the overall pattern, and
therefore the ~? form should emit nothing.

Clearly I'm not understanding something.  Can someone point me in the
right direction?

-- 
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] Running raco setup from within DrRacket?

2019-02-15 Thread Matthias Felleisen



> On Feb 15, 2019, at 11:05 PM, jackhfi...@gmail.com wrote:
> 
> Whenever I change code in my package I switch over to the terminal and 
> recompile it with `raco setup`. This is slightly tedious and I’d like to be 
> able to do this from within DrRacket. But I’m not sure how to translate the 
> command `raco setup --doc-index --check-pkg-deps --tidy --unused-pkg-deps 
> --pkgs ` into a runnable racket module. I tried the following:
>   • Using `system*` didn’t work because it doesn’t search `$PATH` and so 
> it can’t find `raco`.
>   • Using `(find-executable-path "raco")` didn’t work either, it just 
> returned false.
>   • Trying to invoke the setup command using `dynamic-require` and 
> `raco/all-tools` started `raco setup` successfully, but then failed because 
> for some reason the setup command was trying to read and tidy up stale 
> DrRacket-specific zos (the stuff in `compiled/drracket` subdirectories).
> What should I do here? 


See 
https://docs.racket-lang.org/raco/setup-plt-plt.html?q=setup#%28def._%28%28lib._setup%2Fsetup..rkt%29._setup%29%29

(require setup/setup)

I think that’s what you want — 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] Running raco setup from within DrRacket?

2019-02-15 Thread jackhfirth
Whenever I change code in my package I switch over to the terminal and 
recompile it with `raco setup`. This is slightly tedious and I’d like to be 
able to do this from within DrRacket. But I’m not sure how to translate the 
command `raco setup --doc-index --check-pkg-deps --tidy --unused-pkg-deps 
--pkgs ` into a runnable racket module. I tried the following:

   1. Using `system*` didn’t work because it doesn’t search `$PATH` and so 
   it can’t find `raco`.
   2. Using `(find-executable-path "raco")` didn’t work either, it just 
   returned false.
   3. Trying to invoke the setup command using `dynamic-require` and 
   `raco/all-tools` *started* `raco setup` successfully, but then failed 
   because for some reason the setup command was trying to read and tidy up 
   stale DrRacket-specific zos (the stuff in `compiled/drracket` 
   subdirectories).

What should I do here?

-- 
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: Autocomplete from a list

2019-02-15 Thread Greg Hendershott
If the user will choose very frequently (and you want the fastest UX),
and the choices in the database don't change very frequently: It might
be worth experimenting with caching the choices in memory. For
auto-complete I imagine something like a trie, or whatever the latest
hotness might be.

The memory use might be too much to accept. But if the choices have
enough redundancy, the size of the trie might not be awful.

The cache can get stale. How much this matters, depends on your app
and the data. Refreshing every N minutes might be fine? If it's not
fine, and if you're using postgresql, the db lib's postgresql-connect
accepts a notification-handler.

-- 
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 document extending a renderer with a new mixin

2019-02-15 Thread William J. Bowman
I've created a scribble render mixin to call out to pygmentize for typesetting
certain code elements with a certain style.
However, it seems to me that I can't get scribble to use the mixin without
modifying scribble/run.rkt.
I've tried (via rackunit's require/expose) modifying current-render-mixin (which
was a bad idea that wasn't likely to work), and it didn't work.

Am I missing something or should I try to make a patch to that enables scribble
to load a mixin from a given document?

-- 
William J. Bowman

-- 
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] Communicating the purpose of Racket (was: hackernews)

2019-02-15 Thread David Storrs
It looks pretty appealing to me as well.  Clear, concise, and oriented
around pain points that a common developer would have.

On Fri, Feb 15, 2019 at 11:55 AM  wrote:

> I will throw out the Julia homepage (https://www.julialang.org) as a good
> example of language marketing. Perhaps, though, I find the marketing
> effective because it is largely targeted at people like me.
>
>
>
> On Tuesday, February 12, 2019 at 1:18:26 PM UTC-8, Nadeem Abdul Hamid
> wrote:
>>
>> Maybe the mouse-over reveals of each of the 6 blocks on the page should
>> be on a timed animation so they reveal the text detail one by one,
>> independent of the mouse hovering over them? That would provide a
>> gallery-like effect that reveals the prose behind the images.
>>
>>
>> On Tue, Feb 12, 2019 at 3:11 PM Sorawee Porncharoenwase <
>> sorawe...@gmail.com> wrote:
>>
>>> Here's my impression of the homepage.
>>>
>>> [image: Screen Shot 2019-02-12 at 11.33.27.png]
>>>
>>> This is some abstract arts. I don't know what to make out of it.
>>>
>>> --
> 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] Reusing scribble/examples for other languages with external interpreters (Coq)?

2019-02-15 Thread Sorawee Porncharoenwase
Totally!

On Fri, Feb 15, 2019 at 10:15 AM William J. Bowman 
wrote:

> Thanks! Looks pretty helpful to me; at the very least I think I can rip
> out the
> parser and interactive loop.
> I've already got something syntax highlighting by calling off to
> Pygmentize.
>
> Might if I reuse some of that code and put it in a little scribble library?
> (I don't see a license)
>
> --
> William J. Bowman
>
> On Thu, Feb 14, 2019 at 03:49:55PM -0800, Sorawee Porncharoenwase wrote:
> > I did exactly this, but for Pollen. You will want to create a new
> > subprocess with coqtop -emacs 2>&1.
> > You need -emacs because coqtop alone won’t distinguish the message panel
> > and the context panel,
> > and you need 2>&1 because Racket’s merge-input doesn’t preserve the order
> > when merging stderr and stdout.
> >
> > The output is needed to be parsed with regex (that’s how Emacs does it).
> > Note that even though the
> > grammar looks like XML, it will always be one level deep, so using regex
> is
> > fine here.
> >
> >- If you see ..., the thing inside the tag should
> >appear in the message panel.
> >- If you see ..., it means Coq has processed a new
> >command
> >(such as a focus or a command terminating with dot). The information
> >inside is not useful for me, but it might be for you.
> >- If you see Toplevel input, your code has an error.
> >
> > If it’s helpful (I don’t think it will), here’s my work-in-progress code
> > <
> https://github.com/sorawee/my-website/blob/master/coq-tactics/pollen.rkt#L66
> >
> > which is used to generate this page
> > .
> >
> > On Thu, Feb 14, 2019 at 3:09 PM William J. Bowman <
> w...@williamjbowman.com>
> > wrote:
> >
> > > Does anyone have work adapting or hi-jacking scribble/examples to run
> code
> > > from
> > > other languages, particularly for non-sexpr languages that require
> calling
> > > out
> > > to an external interpreter?
> > >
> > > In particular, I want to make it work for Coq programs so I can write
> nice
> > > scribble documents with embedded Coq examples.
> > > I could partially reimplement a scribble/examples-like macro that
> spins up
> > > a
> > > subprocess to interact with coqtop, but I was hoping someone might have
> > > some
> > > work I can reuse.
> > >
> > > --
> > > William J. Bowman
> > >
> > > --
> > > 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] Reusing scribble/examples for other languages with external interpreters (Coq)?

2019-02-15 Thread William J. Bowman
Thanks! Looks pretty helpful to me; at the very least I think I can rip out the
parser and interactive loop.
I've already got something syntax highlighting by calling off to Pygmentize.

Might if I reuse some of that code and put it in a little scribble library?
(I don't see a license)

--
William J. Bowman

On Thu, Feb 14, 2019 at 03:49:55PM -0800, Sorawee Porncharoenwase wrote:
> I did exactly this, but for Pollen. You will want to create a new
> subprocess with coqtop -emacs 2>&1.
> You need -emacs because coqtop alone won’t distinguish the message panel
> and the context panel,
> and you need 2>&1 because Racket’s merge-input doesn’t preserve the order
> when merging stderr and stdout.
> 
> The output is needed to be parsed with regex (that’s how Emacs does it).
> Note that even though the
> grammar looks like XML, it will always be one level deep, so using regex is
> fine here.
> 
>- If you see ..., the thing inside the tag should
>appear in the message panel.
>- If you see ..., it means Coq has processed a new
>command
>(such as a focus or a command terminating with dot). The information
>inside is not useful for me, but it might be for you.
>- If you see Toplevel input, your code has an error.
> 
> If it’s helpful (I don’t think it will), here’s my work-in-progress code
> 
> which is used to generate this page
> .
> 
> On Thu, Feb 14, 2019 at 3:09 PM William J. Bowman 
> wrote:
> 
> > Does anyone have work adapting or hi-jacking scribble/examples to run code
> > from
> > other languages, particularly for non-sexpr languages that require calling
> > out
> > to an external interpreter?
> >
> > In particular, I want to make it work for Coq programs so I can write nice
> > scribble documents with embedded Coq examples.
> > I could partially reimplement a scribble/examples-like macro that spins up
> > a
> > subprocess to interact with coqtop, but I was hoping someone might have
> > some
> > work I can reuse.
> >
> > --
> > William J. Bowman
> >
> > --
> > 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] Communicating the purpose of Racket (was: hackernews)

2019-02-15 Thread travis . hinkelman
I will throw out the Julia homepage (https://www.julialang.org) as a good 
example of language marketing. Perhaps, though, I find the marketing 
effective because it is largely targeted at people like me.



On Tuesday, February 12, 2019 at 1:18:26 PM UTC-8, Nadeem Abdul Hamid wrote:
>
> Maybe the mouse-over reveals of each of the 6 blocks on the page should be 
> on a timed animation so they reveal the text detail one by one, independent 
> of the mouse hovering over them? That would provide a gallery-like effect 
> that reveals the prose behind the images.
>
>
> On Tue, Feb 12, 2019 at 3:11 PM Sorawee Porncharoenwase <
> sorawe...@gmail.com > wrote:
>
>> Here's my impression of the homepage.
>>
>> [image: Screen Shot 2019-02-12 at 11.33.27.png]
>>
>> This is some abstract arts. I don't know what to make out of it.
>>
>>

-- 
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] Contracts question on structs

2019-02-15 Thread Chris GauthierDickey
Still having trouble though, can't get struct/dc to work in the way I'd
like. I tried to simplify my example:

(define Result/c
  (struct/dc Result
 (a number?)
 (b boolean?)
 ; in other words, if a is 0, then b must be
 ; false or the contract is broken
 #:inv (a b) (if (= a 0)
 (eq? b #f)
 #t)))
(provide (contract-out [Result Result/c]))

The documentation on #:inv says it must return a non-#f value, which I
assume means it acts like a predicate? #f if the contract fails, something
else otherwise? In any case, this doesn't work because it says:

Result: broke its own contract
  promised: Result?
  produced: #
  in: (struct/dc
   Result
   (a number?)
   (b boolean?)
   #:inv
   (a b)
   ...)

I also tried specifying all of the struct functions that are created with
their own contracts, like Result-a, Result-b, Result? and then using
Result/c for Result, and this fails too.

I think I understand how this is being used in the example in the
documentation with #:lazy, but it's not quite what I'm looking for: I'm
looking to use a contract on the struct constructor (in particular, which
is why I thought #:inv would be the way to go) where one field
initialization depends on another.

As an aside, I also tried the following:

(provide (contract-out [Result (or/c (number? boolean? . -> . Result?)
 (0 #f . -> . Result?))]))

But the contract system complained that both might match (I mean I can see
that one is more specific, but I understand it's not a theorem prover,
haha).

Thoughts?
Chris

On Fri, Feb 15, 2019 at 7:56 AM Chris GauthierDickey 
wrote:

> I believe it should be since bst/c is supposed to be a contract. Also I
> noticed the docs at
> https://docs.racket-lang.org/reference/data-structure-contracts.html show
> a similar example:
>
> ; bst-between : number number -> contract
> ; builds a contract for binary search trees
> ; whose values are between low and high
> (define (bst-between/c low high)
>   (or/c null?
> (struct/dc node [val (between/c low high)]
> [left (val) #:lazy (bst-between/c low val)]
> [right (val) #:lazy (bst-between/c val high)])))
>
>
> On Fri, Feb 15, 2019 at 1:31 AM David Storrs 
> wrote:
>
>> On Fri, Feb 15, 2019 at 12:18 AM David Storrs 
>> wrote:
>> >
>> > On Thu, Feb 14, 2019 at 9:08 PM Robby Findler
>> >  wrote:
>> > >
>> > > This is what struct/dc is for. Let me know if the docs let you down!
>> > >
>> > > Robby
>> >
>> > This is good to hear about, because I'm actually in the middle of
>> > writing something that it will help with.  Thanks, Robby.
>> >
>> > One question:  Is there a typo in the example code or am I missing
>> something?
>> >
>> > (struct bt (val left right))
>> > (define (bst/c lo hi)
>> > (or/c #f
>> > (struct/dc bt
>> > [val (between/c lo hi)]
>> > [left (val) #:lazy (bst lo val)]   ; should that be (bt
>> lo val)?
>> > [right (val) #:lazy (bst val hi)]))) ; and this be (bt val
>> hi) ?
>>
>> Ugh.  I hate it when I make significant typos in code questions.  I
>> should have asked if it was supposed to (bst/c lo val) and (bst/c val
>> hi). (i.e., is there a missing /c in the code?)  If not, where is bst
>> defined?
>>
>> >
>> > Also, am I correct that the contract is not actually attached to the
>> > bt structure at this point?  That's a thing that would be done
>> > elsewhere, probably in the provide statement.  Yes?
>> >
>> > >
>> > > On Thu, Feb 14, 2019 at 7:57 PM Chris GauthierDickey <
>> chris...@gmail.com> wrote:
>> > >>
>> > >> I'm wondering if it's possible to have a contract for a struct that
>> only allows certain kinds of initializations. For example, I have this:
>> > >>
>> > >> (provide (contract-out
>> > >>   [struct Result ((name (or/c Temp? Label?)) (global?
>> boolean?) (value (or/c VarValue? #f)))]))
>> > >>
>> > >> But it's too general. What I'd really like to have is a contract
>> that combines them like an or/c (I can see what this would cause problems,
>> just wondering if there's a clever way around it):
>> > >> (provide (contract-out
>> > >>   [or/c (struct Result ((name Temp?) (global? #f) (value
>> (or/c VarValue? #f
>> > >> (struct Result ((name Label?) (global? boolean?)
>> (value (or/c (VarValue #f)]))
>> > >>
>> > >> In this case, if name is Temp? then global? has to be #f. If name is
>> Label? then global? can be #t or #f. I'd like to use struct cause it
>> provides all the contracts for accessors and such. Note, I can use a
>> #:guard on the struct, but wondered if it was possible to do something
>> along these lines with a contract.
>> > >>
>> > >> Thanks!
>> > >> Chris
>> > >>
>> > >>
>> > >> --
>> > >> You received this message because you are subscribed to the Google
>> Groups "Racket Users" group.
>> > >> To unsubscribe f

Re: [racket-users] Contracts question on structs

2019-02-15 Thread Chris GauthierDickey
I believe it should be since bst/c is supposed to be a contract. Also I
noticed the docs at
https://docs.racket-lang.org/reference/data-structure-contracts.html show a
similar example:

; bst-between : number number -> contract
; builds a contract for binary search trees
; whose values are between low and high
(define (bst-between/c low high)
  (or/c null?
(struct/dc node [val (between/c low high)]
[left (val) #:lazy (bst-between/c low val)]
[right (val) #:lazy (bst-between/c val high)])))


On Fri, Feb 15, 2019 at 1:31 AM David Storrs  wrote:

> On Fri, Feb 15, 2019 at 12:18 AM David Storrs 
> wrote:
> >
> > On Thu, Feb 14, 2019 at 9:08 PM Robby Findler
> >  wrote:
> > >
> > > This is what struct/dc is for. Let me know if the docs let you down!
> > >
> > > Robby
> >
> > This is good to hear about, because I'm actually in the middle of
> > writing something that it will help with.  Thanks, Robby.
> >
> > One question:  Is there a typo in the example code or am I missing
> something?
> >
> > (struct bt (val left right))
> > (define (bst/c lo hi)
> > (or/c #f
> > (struct/dc bt
> > [val (between/c lo hi)]
> > [left (val) #:lazy (bst lo val)]   ; should that be (bt
> lo val)?
> > [right (val) #:lazy (bst val hi)]))) ; and this be (bt val
> hi) ?
>
> Ugh.  I hate it when I make significant typos in code questions.  I
> should have asked if it was supposed to (bst/c lo val) and (bst/c val
> hi). (i.e., is there a missing /c in the code?)  If not, where is bst
> defined?
>
> >
> > Also, am I correct that the contract is not actually attached to the
> > bt structure at this point?  That's a thing that would be done
> > elsewhere, probably in the provide statement.  Yes?
> >
> > >
> > > On Thu, Feb 14, 2019 at 7:57 PM Chris GauthierDickey <
> chris...@gmail.com> wrote:
> > >>
> > >> I'm wondering if it's possible to have a contract for a struct that
> only allows certain kinds of initializations. For example, I have this:
> > >>
> > >> (provide (contract-out
> > >>   [struct Result ((name (or/c Temp? Label?)) (global?
> boolean?) (value (or/c VarValue? #f)))]))
> > >>
> > >> But it's too general. What I'd really like to have is a contract that
> combines them like an or/c (I can see what this would cause problems, just
> wondering if there's a clever way around it):
> > >> (provide (contract-out
> > >>   [or/c (struct Result ((name Temp?) (global? #f) (value
> (or/c VarValue? #f
> > >> (struct Result ((name Label?) (global? boolean?)
> (value (or/c (VarValue #f)]))
> > >>
> > >> In this case, if name is Temp? then global? has to be #f. If name is
> Label? then global? can be #t or #f. I'd like to use struct cause it
> provides all the contracts for accessors and such. Note, I can use a
> #:guard on the struct, but wondered if it was possible to do something
> along these lines with a contract.
> > >>
> > >> Thanks!
> > >> 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.
> > >> 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.


[racket-users] Racket News - Issue 2

2019-02-15 Thread 'Paulo Matos' via Racket Users
I have just published Issue 2 at

http://racket-news.com/2019/02/racket-news-issue-2.html


I would have loved to send a text version to the mailing list but with
code and images to render I haven't found a way to do this properly yet.
I have tried scribble --text and pandoc but both had shortcomings.

For now, please refer to the web address. If you have suggestions please
let me know.

Grab a coffee and enjoy!

-- 
Paulo Matos

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