Re: [racket-users] how do I remove a specified collection?

2022-08-10 Thread David Storrs
The problem is more likely to do with the shell misunderstanding '?', but
you can find a collection using:
https://docs.racket-lang.org/raco-fc/index.html

On Mon, Aug 8, 2022 at 11:31 AM Don Green 
wrote:

> $ raco setup ?
> collection-path: collection not found
>   collection: "t"
>
> How do I go about finding and removing: collection: "t"  ?
> 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/57fecc34-3485-415b-8c9d-fcb57ef4d15cn%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/CAE8gKod%3DJb7To0_YJPUWjPDLJ-Z1Ndq8Jzqw6u-4p%3DzXWyeVtA%40mail.gmail.com.


Re: [racket-users] Combining contract checking with normalization?

2022-03-07 Thread David Storrs
Would this give part of what you're looking for?

#lang racket

(define (my-string-length s)
  ((or/c (and/c (or/c symbol? string?) (compose1 string-length ~a))
 (curry raise-arguments-error 'my-string-length "invalid arg"
"arg"))
   s))

(my-string-length "foo")
(my-string-length 'foo)
(my-string-length 7)


It's not something you'd want to write by hand in a lot of places, but it
seems an easy target for a macro.


On Sun, Mar 6, 2022 at 10:47 AM Alexis King  wrote:

> Hello,
>
> As a user of the Racket contract system, I sometimes find myself thinking
> about the potential utility of “coercing” or “canonicalizing” contracts. In
> Racket programs, we often idiomatically allow values to be provided to a
> function in a non-canonical form for the sake of convenience. One example
> is the commonly-used path-string? contract, which is morally equivalent
> to using path? but allows the caller to omit an explicit use of
> string->path. Another example is the commonly-used failure-result/c
> contract, which allows the caller to omit wrapping non-procedures in a
> thunk.
>
> While this idiom does make life easier for one party to the contract, it
> ultimately just transfers the burden of canonicalizing the value to the
> other party. This is unfortunate, because it results in a duplication of
> both logic and work:
>
>-
>
>Code to canonicalize the value must be written separately and kept in
>sync with the contract, which is error-prone.
>-
>
>The value ends up being inspected twice: once to determine if it
>satisfies the contract, and a second time to convert it to canonical form.
>
> (In the nomenclature of a popular blog post I wrote a few years ago, these
> contracts are validating, not parsing
> .)
>
> In theory, it is perfectly possible to implement a canonicalizing contract
> using the current contract system. However, such a contract has several
> practical downsides:
>
>-
>
>It is necessarily an impersonator contract, not a chaperone contract.
>This prevents its use in places that demand a chaperone contract, such as
>the *key* argument to hash/c.
>-
>
>It moves actual logic into the contract itself, which means using the
>uncontracted value directly is less convenient. This encourages placing the
>contract boundary close to the value’s definition to create a very small
>contracted region (e.g. via define/contract), even though blame is
>generally more useful when the contract boundary corresponds to a boundary
>between higher-level components (e.g. via contract-out).
>-
>
>There is no way to write such contracts using the combinators provided
>by racket/contract, so they must be implemented via the lower level
>make-contract/build-contract-property API. This can be subtle to use
>correctly, and it makes it unlikely that contract violations made by the
>contract itself will be blamed properly according to the “indy” blame
>semantics used by ->i.
>
> All this is to say that the current contract system clearly discourages
> this use of contracts, which suggests this would be considered an abuse of
> the contract system. Nevertheless, the coupling between validating values
> and converting them to a normal form is so enormously tight that allowing
> them to be specified together remains incredibly compelling. I therefore
> have two questions:
>
>1.
>
>Has this notion of “canonicalizing” contracts been discussed before,
>whether in informal discussions or in literature?
>2.
>
>Is there any existing work that explores what adding such contracts to
>a Racket-style, higher-order contract system in a principled fashion might
>look like?
>
> Thanks in advance,
> Alexis
>
> --
> 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/CAA8dsad%2BZHLQTBK-oa5UZJfV7t33Fk0Q0L5rTG-CBnzMqH3haA%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/CAE8gKoeEQYAy6J63MyCxFTmQ6rneUXhsj9DD10-shpwL7GGUFQ%40mail.gmail.com.


Re: [racket-users] looking for advice on a web background process manager

2022-01-06 Thread David Storrs
Speaking of existing task managers:
https://docs.racket-lang.org/majordomo2/index.html   



On Wed, Jan 5, 2022 at 7:31 PM Stefan Schwarzer 
wrote:

> On 2021-12-30 21:33, 'Wayne Harris' via Racket Users wrote:
> > I'm considering writing a manager for background processes --- such as
> send a batch of e-mail or other process that takes a while to finish ---
> for a web system.
> >
> > I see the challenge here as just writing something that will look like a
> > very basic UNIX shell --- so I'll call it ``web-api-shell'' from now on.
> > (``Web'' because it will be used by a web system through some HTTP API.)
> >
> > This thing has to be flawless. I'm looking for design principles and
> advice.
> > [...]
>
> Have you looked at existing task queues and message brokers?
> I guess they can already give you a part of the robustness
> you're looking for. It would be a pity to reinvent the wheel,
> especially since it will probably be quite difficult and
> time-consuming to implement this robustness yourself.
>
> But it might as well be that I misunderstand your requirements.
> :-)
>
> Stefan
>
> --
> 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/ddeb9170-6273-34be-ec6d-7edc8b3a4146%40sschwarzer.net
> .
>

-- 
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/CAE8gKodc9w5wj5EksihxQGm%3Dc_%3D7vrkpD8iJtpmHrE6UATqKaA%40mail.gmail.com.


[racket-users] Happy holidays to all

2021-12-25 Thread David Storrs
Happy holidays, everyone.  The Racket community has been very welcoming and
helpful to me over the years, and everyone here is a lovely person.  I hope
you're all having a lovely holiday.

Dave

-- 
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/CAE8gKoda-YfoTnWwszJvBYHWt2qHM3%3Do%2BQpABP9bV7qmC%3DzTgw%40mail.gmail.com.


Re: [racket-users] Beginner's question

2021-12-14 Thread David Storrs
Jens answered your question, but I'll note two convenient shorthands:

> #lang racket
> (require racket/format)

racket/format is provided by #lang racket, so you can skip that.

This:

(define fp
  (lambda (s n)
(string-append (pp_number n) " + " s)))

is the same as this:

(define (fp s n)
(string-append (pp_number n) " + " s)))



On Tue, Dec 14, 2021 at 1:48 PM Cyrille DEUSS 
wrote:

> #lang racket
> (require racket/format)
>
> (define pp_number
>   (lambda (n)
>  (~a n #:width 6 #:align 'right  #:left-pad-string "0")))
>
> (define fp
>   (lambda (s n)
> (string-append (pp_number n) " + " s)))
>
> (define f
>   (lambda (s n)
> (format "~a + ~a" n s)))
>
> (foldl f "" '(1 2 3))
> ; works great !
>
> (foldl fp "" '(1 2 3))
> ; and why not this one ?
>
> Thanks in advance.
> Cyrille
>
> --
> 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/e72b954e-0b48-4830-b253-34b904d726bcn%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/CAE8gKoeiVYvsCFuJgHYvK9Eg7cDpSTAkGpk4h2x8aNoe8YHOzg%40mail.gmail.com.


Re: the end of the [racket-users] mailing list and the migration to Discourse as a forum for Racket

2021-11-22 Thread David Storrs
That's sudden.

On Mon, Nov 22, 2021 at 8:06 AM Etan Wexler  wrote:

> The stewards of Racket  have decided that it’s
> time to give up on the mailing list (that is, racket-users
> , to which this message is
> a contribution). The stewards of Racket  have
> designated another forum for Racket  as
> the successor to racket-users
> . This other forum for
> discussing Racket  has as its basis the
> software named “Discourse” , which is
> open‐source. Enlisting is prerequisite to contributing to the Discursive
> forum for Racket . Enlisting is
> prerequisite to receiving as Internet mail the contributions to the
> Discursive forum for Racket . The
> stewards of Racket  have published a facility
> for enlisting as a participant in the Discursive forum for Racket
> .
>

-- 
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/CAE8gKoewCWhqGkxcxq%2BMD7ZUjphXNj9j7bx0bw2%2BzTCWFSSHog%40mail.gmail.com.


Re: [racket-users] racket-mode / paredit combine closing parens

2021-11-17 Thread David Storrs
Ah, that looks right.  Thanks, Siddhartha.

On Wed, Nov 17, 2021 at 1:59 PM Siddhartha Kasivajhula 
wrote:

> Was curious about this feature so I went looking. It might be lispy-tab
> <http://oremacs.com/lispy/#lispy-tab>.
>
>
> On Wed, Nov 17, 2021 at 10:35 AM David Storrs 
> wrote:
>
>> In Emacs, I've seen a demonstration where one keystroke can pull all
>> closing parens together, transforming this (point/cursor position is shown
>> as |):
>>
>> (let ()
>>   (let ()
>>(some-func 'a)|
>>   )
>> )
>>
>> into this:
>>
>> (let ()
>>   (let ()
>>(some-func 'a)))|
>>
>> I haven't been able to find the relevant keyboard command.  Does anyone
>> know it?  I'm not sure if it's racket-mode, paredit, or some other thing.
>>
>> --
>> 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/CAE8gKofPAMdVQK1Aw_WjB7wcdhxNST10itriV6a0SbGgKNaB9A%40mail.gmail.com
>> <https://groups.google.com/d/msgid/racket-users/CAE8gKofPAMdVQK1Aw_WjB7wcdhxNST10itriV6a0SbGgKNaB9A%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
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/CAE8gKod5%2B5iYTicW8qS8bUKPMkXy-GDQdrN229T1Uz1rTwwSrQ%40mail.gmail.com.


[racket-users] racket-mode / paredit combine closing parens

2021-11-17 Thread David Storrs
In Emacs, I've seen a demonstration where one keystroke can pull all
closing parens together, transforming this (point/cursor position is shown
as |):

(let ()
  (let ()
   (some-func 'a)|
  )
)

into this:

(let ()
  (let ()
   (some-func 'a)))|

I haven't been able to find the relevant keyboard command.  Does anyone
know it?  I'm not sure if it's racket-mode, paredit, or some other thing.

-- 
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/CAE8gKofPAMdVQK1Aw_WjB7wcdhxNST10itriV6a0SbGgKNaB9A%40mail.gmail.com.


Re: [racket-users] Best way to append an element to a list?

2021-11-16 Thread David Storrs
Cool, thank you.

On Tue, Nov 16, 2021 at 2:15 PM Sage Gerard  wrote:

> I get these timings on x86_64 GNU/Linux using the following profile
> program.
>
> ; A: cpu time: 7444 real time: 7445 gc time:
> 716
> ; B: cpu time: 9227 real time: 9228 gc time: 884
>
> (module profile racket/base
>   (define target-length #e5e4)
>
>   (define (A current-list new-element)
> (append current-list (list new-element)))
>
>   (define (B current-list new-element)
> (reverse (cons new-element  (reverse current-list
>
>   (define (profile function)
> (printf "~a: " (object-name function))
> (time
>  (void (for/fold ([l null])
>  ([n (in-range target-length)])
>  (function l n)))))
>
>   (profile A)
>   (profile B))
>
> On 11/16/21 2:04 PM, David Storrs wrote:
>
> If I want to add an element to the end of an immutable list, is it better
> to do:
>
> (append current-list (list new-element))
> or
> (reverse (cons new-element  (reverse current-list)))
> or
> something else?
>
> I would imagine it's the first one because that should be a single
> traversal and link add instead of two traversals and rebuilds, but maybe
> I'm wrong.
> --
> 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/CAE8gKocM4jNCg6xKruYwuwFtuOdbOSwugYcgUND1ZD%3DRB1iA0g%40mail.gmail.com
> <https://groups.google.com/d/msgid/racket-users/CAE8gKocM4jNCg6xKruYwuwFtuOdbOSwugYcgUND1ZD%3DRB1iA0g%40mail.gmail.com?utm_medium=email_source=footer>
> .
>
> --
> 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/3a9777e7-4b33-b561-f47e-8fe940699b39%40sagegerard.com
> <https://groups.google.com/d/msgid/racket-users/3a9777e7-4b33-b561-f47e-8fe940699b39%40sagegerard.com?utm_medium=email_source=footer>
> .
>

-- 
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/CAE8gKocmkK%2B4mwEZEvib-E63g9uYfzMh_p2HLz_07pSWkJ%2BY3A%40mail.gmail.com.


[racket-users] Best way to append an element to a list?

2021-11-16 Thread David Storrs
If I want to add an element to the end of an immutable list, is it better
to do:

(append current-list (list new-element))
or
(reverse (cons new-element  (reverse current-list)))
or
something else?

I would imagine it's the first one because that should be a single
traversal and link add instead of two traversals and rebuilds, but maybe
I'm wrong.

-- 
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/CAE8gKocM4jNCg6xKruYwuwFtuOdbOSwugYcgUND1ZD%3DRB1iA0g%40mail.gmail.com.


Re: [racket-users] How to learn the *core* of Racket?

2021-11-11 Thread David Storrs
Out of curiosity, what is it that you're trying to achieve here?  You're
not going to program in the fully-expanded language, you're going to
program in something higher level.  Is this purely a "learning assembly
code is good because it gives you a better understanding of machine
architecture" thing?

On Sat, Nov 6, 2021 at 5:33 AM Yushuo Xiao  wrote:

> I've learned some Racket, and can comfortably program in it, but I only
> learned it as an ordinary language, much like Scheme. I know Racket is much
> more than that, for its "language-oriented" features. Languages become a
> first-class member in Racket, and to my understanding, even "#lang racket"
> is just a language built on some core. What I want to know is, what's the
> very core of Racket?
>
> I've noticed that in the Racket Reference there is a section "Fully
> Expanded Programs", which seems the very core of Racket. But it still takes
> an S-expression form, and apparently Racket allows language customization
> on the syntax level. I wonder if the S-expression language is the core of
> Racket, or the entire Racket has a different structure?
>
> I would really appreciate it if anyone could explain it in a simple way or
> could point out some good (and short) material for me to read. The Racket
> Reference is too long, and I believe the core Racket can be well explained
> in a much shorter piece of text, if I just look for a brief understanding.
>
> Also my question may be confusing, because I don't understand Racket well
> at all. Feel free to correct me or ask for clarification. Thanks in advance!
>
> --
> 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/63b1134b-16e4-4447-828a-1e607013bd7cn%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/CAE8gKocDJQZjJc1WBBQpFekUsJLC_HN4quDXkgPmLXDQ9PEy6A%40mail.gmail.com.


Re: [racket-users] How to learn the *core* of Racket?

2021-11-11 Thread David Storrs
Sure, that's as good a definition as any.

On Thu, Nov 11, 2021, 6:04 AM Yushuo Xiao  wrote:

> Thank you for your comprehensive answer! It helps a lot. I also read more
> about Racket after I posted the question and now I think that the few
> special forms (as stated in "fully expanded program") are the core. All
> languages built in Racket will parse and convert their syntax into syntax
> objects (S-expressions) and then expand to these special forms. Am I right?
>
> On Sunday, November 7, 2021 at 6:53:53 AM UTC+8 david@gmail.com wrote:
>
>> Hi Yushuo,
>>
>> On Sat, Nov 6, 2021 at 5:33 AM Yushuo Xiao  wrote:
>>
>>> I've learned some Racket, and can comfortably program in it, but I only
>>> learned it as an ordinary language, much like Scheme. I know Racket is much
>>> more than that, for its "language-oriented" features. Languages become a
>>> first-class member in Racket, and to my understanding, even "#lang racket"
>>> is just a language built on some core. What I want to know is, what's the
>>> very core of Racket?
>>
>>
>> It depends on where you stop measuring.  You could argue that...
>>
>> ...#lang racket  is the core, because it's what comes in the
>> installation.  Things like gregor, struct-plus-plus, and csv-reading are
>> packages that you install from http://pkgs.racket-lang.org/ and are
>> therefore outside the core.
>>
>> ...#lang racket/base is the core, because it's the most limited set of
>> Racket that comes by default.  It mostly consists of only the basic list
>> manipulation functions, and if you want to use other things then you need
>> to include relevant libraries such as racket/match (giving you the 'match'
>> special form) or racket/format (giving you the ~a function), or
>> racket-string (giving you the string-length function), etc.
>>
>> ...Raw lambdas and a few special forms are the core, because everything
>> compiles down to those.  (Approximately speaking.)
>>
>> ...Lambda calculus is the core, because it's what all LISP descendants
>> are based on.
>>
>> Once you start talking about other Racket languages with different syntax
>> and semantics, well then all bets are off.
>>
>>
>> Does this help?
>>
>>
>>> I've noticed that in the Racket Reference there is a section "Fully
>>> Expanded Programs", which seems the very core of Racket. But it still takes
>>> an S-expression form, and apparently Racket allows language customization
>>> on the syntax level. I wonder if the S-expression language is the core of
>>> Racket, or the entire Racket has a different structure?
>>>
>>> I would really appreciate it if anyone could explain it in a simple way
>>> or could point out some good (and short) material for me to read. The
>>> Racket Reference is too long, and I believe the core Racket can be well
>>> explained in a much shorter piece of text, if I just look for a brief
>>> understanding.
>>>
>>> Also my question may be confusing, because I don't understand Racket
>>> well at all. Feel free to correct me or ask for clarification. Thanks in
>>> advance!
>>>
>>> --
>>> 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...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/racket-users/63b1134b-16e4-4447-828a-1e607013bd7cn%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/6929457c-459f-4c25-94c0-ea973b121c65n%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/CAE8gKoc-8rGaY%2BF2nDLR5BULe1tGnO5BnGAZt-DgBmhCVg_9dw%40mail.gmail.com.


Re: [racket-users] How to learn the *core* of Racket?

2021-11-06 Thread David Storrs
Hi Yushuo,

On Sat, Nov 6, 2021 at 5:33 AM Yushuo Xiao  wrote:

> I've learned some Racket, and can comfortably program in it, but I only
> learned it as an ordinary language, much like Scheme. I know Racket is much
> more than that, for its "language-oriented" features. Languages become a
> first-class member in Racket, and to my understanding, even "#lang racket"
> is just a language built on some core. What I want to know is, what's the
> very core of Racket?


It depends on where you stop measuring.  You could argue that...

...#lang racket  is the core, because it's what comes in the installation.
Things like gregor, struct-plus-plus, and csv-reading are packages that you
install from http://pkgs.racket-lang.org/ and are therefore outside the
core.

...#lang racket/base is the core, because it's the most limited set of
Racket that comes by default.  It mostly consists of only the basic list
manipulation functions, and if you want to use other things then you need
to include relevant libraries such as racket/match (giving you the 'match'
special form) or racket/format (giving you the ~a function), or
racket-string (giving you the string-length function), etc.

...Raw lambdas and a few special forms are the core, because everything
compiles down to those.  (Approximately speaking.)

...Lambda calculus is the core, because it's what all LISP descendants are
based on.

Once you start talking about other Racket languages with different syntax
and semantics, well then all bets are off.


Does this help?


> I've noticed that in the Racket Reference there is a section "Fully
> Expanded Programs", which seems the very core of Racket. But it still takes
> an S-expression form, and apparently Racket allows language customization
> on the syntax level. I wonder if the S-expression language is the core of
> Racket, or the entire Racket has a different structure?
>
> I would really appreciate it if anyone could explain it in a simple way or
> could point out some good (and short) material for me to read. The Racket
> Reference is too long, and I believe the core Racket can be well explained
> in a much shorter piece of text, if I just look for a brief understanding.
>
> Also my question may be confusing, because I don't understand Racket well
> at all. Feel free to correct me or ask for clarification. Thanks in advance!
>
> --
> 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/63b1134b-16e4-4447-828a-1e607013bd7cn%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/CAE8gKodVp3XKRnQc165F%2Bav001L86BOvTE_sPvdrpkx5FY4VdQ%40mail.gmail.com.


Re: [racket-users] How to discover a struct's interface without Dr Racket?

2021-10-31 Thread David Storrs
The actual accessor functions are in there as well, not just the names.

On Sun, Oct 31, 2021, 9:58 AM Jens Axel Søgaard 
wrote:

> A quick example:
>
> #lang racket
> (require racket/require)
> (require (filtered-in (λ (name) (regexp-replace #rx"struct[+][+]" name
> "struct"))
>   struct-plus-plus))
>
> (struct horse (breed color legs))
>
> (define beauty (horse 'arabian 'black 4))
>
> (define info (force (struct-ref beauty)))
> (map struct-field-name (struct-info-fields info))
>
> The result is:
> '(breed color legs)
>
> Den søn. 31. okt. 2021 kl. 13.06 skrev David Storrs <
> david.sto...@gmail.com>:
>
>>
>>
>> On Sun, Oct 31, 2021, 7:49 AM Jens Axel Søgaard 
>> wrote:
>>
>>> Hi Brian,
>>>
>>> A few random thoughts:
>>>
>>> > I would like, given only the symbol foo referring to the struct type
>>> itself,
>>> > to discover (at least) the list of procedures foo?, foo-a, foo-b, plus
>>> > anything else the author of foo (the type) wants me to see.
>>>
>>> When you want to look this up, is it in the repl (i.e. at runtime)?
>>>
>>> The standard `struct` construct doesn't store much reflection
>>> information.
>>> Instead of fighting the standard construct, you can consider making a
>>> little variation.
>>>
>>> If you are satisfied with having info for the structs defined in your
>>> own program
>>> (i.e. modules you have written yourself), then you can consider making a
>>> module, say, `fancy-struct` that exports a macro where
>>>
>>>(fancy-struct yada ...)
>>>
>>> expands into
>>>
>>>(begin
>>>   (fancy-struct yada ...)
>>>   )
>>>
>>> Using `rename-out` you can export it as `struct`, so it can be used
>>> without changing any existing code.
>>>
>>> /Jens Axel
>>>
>>
>> Coincidentally, that module exists!
>>
>>
>> https://docs.racket-lang.org/struct-plus-plus/index.html#%28part._.Reflection%29
>>
>>
>>
>>>
>>>
>>> Den søn. 31. okt. 2021 kl. 11.42 skrev Matt Jadud :
>>>
>>>> Hi Brian,
>>>>
>>>> Does this help move you forward?
>>>>
>>>> It has been a while since I've stared at macros in Racket, so this
>>>> might be easier...
>>>>
>>>> Also, make sure you're executing this code in a module. If you're
>>>> working in a REPL, I suspect all bets are off. It is certainly the case
>>>> that you could combine several of my exploration steps into a
>>>> simpler/cleaner macro, instead of generating lists of symbols, converting
>>>> them back to syntax objects, and so on.
>>>>
>>>> Also, as a solution/exploration, I... don't know how this would
>>>> interact with the full range of possible structs. Someone who knows more
>>>> about syntax and structs should be able to speak to how you'd find out all
>>>> of the defined functions that spawn from struct definition/creation. (It
>>>> might also be useful to know *why* you want to destructure structs this
>>>> way? Knowing that may illuminate some other path forward.)
>>>>
>>>> #lang racket
>>>> (require racket/struct-info)
>>>>
>>>> (struct A (b c))
>>>>
>>>> (struct B (e f) #:transparent)
>>>>
>>>> (require (for-syntax racket/struct-info))
>>>> (define-syntax (get-field-names stx)
>>>>   (syntax-case stx ()
>>>> [(_ sym)
>>>>  #`(quote
>>>> #,(struct-field-info-list
>>>>(syntax-local-value #'sym)))
>>>>   ]))
>>>>
>>>> ;; These let me see the field names
>>>> (get-field-names A)
>>>> ;; Returns '(c b)
>>>> (get-field-names B)
>>>> ;; Returns '(f e)
>>>>
>>>> ;;
>>>> https://stackoverflow.com/questions/20076868/how-to-know-whether-a-racket-variable-is-defined-or-not
>>>> (define-syntax (defined? stx)
>>>>   (syntax-case stx ()
>>>> [(_ id)
>>>>  (with-syntax ([v (identifier-binding #'id)])
>>>>#''v)]))
>>>>
>>>> (define-syntax (proc-names stx)
>>>>   (syntax-case stx ()
>>>> [(_ sym)
>>>>  (let ([names (map 

Re: [racket-users] How to discover a struct's interface without Dr Racket?

2021-10-31 Thread David Storrs
On Sun, Oct 31, 2021, 7:49 AM Jens Axel Søgaard 
wrote:

> Hi Brian,
>
> A few random thoughts:
>
> > I would like, given only the symbol foo referring to the struct type
> itself,
> > to discover (at least) the list of procedures foo?, foo-a, foo-b, plus
> > anything else the author of foo (the type) wants me to see.
>
> When you want to look this up, is it in the repl (i.e. at runtime)?
>
> The standard `struct` construct doesn't store much reflection information.
> Instead of fighting the standard construct, you can consider making a
> little variation.
>
> If you are satisfied with having info for the structs defined in your own
> program
> (i.e. modules you have written yourself), then you can consider making a
> module, say, `fancy-struct` that exports a macro where
>
>(fancy-struct yada ...)
>
> expands into
>
>(begin
>   (fancy-struct yada ...)
>   )
>
> Using `rename-out` you can export it as `struct`, so it can be used
> without changing any existing code.
>
> /Jens Axel
>

Coincidentally, that module exists!

https://docs.racket-lang.org/struct-plus-plus/index.html#%28part._.Reflection%29



>
>
> Den søn. 31. okt. 2021 kl. 11.42 skrev Matt Jadud :
>
>> Hi Brian,
>>
>> Does this help move you forward?
>>
>> It has been a while since I've stared at macros in Racket, so this might
>> be easier...
>>
>> Also, make sure you're executing this code in a module. If you're working
>> in a REPL, I suspect all bets are off. It is certainly the case that you
>> could combine several of my exploration steps into a simpler/cleaner macro,
>> instead of generating lists of symbols, converting them back to syntax
>> objects, and so on.
>>
>> Also, as a solution/exploration, I... don't know how this would interact
>> with the full range of possible structs. Someone who knows more about
>> syntax and structs should be able to speak to how you'd find out all of the
>> defined functions that spawn from struct definition/creation. (It might
>> also be useful to know *why* you want to destructure structs this way?
>> Knowing that may illuminate some other path forward.)
>>
>> #lang racket
>> (require racket/struct-info)
>>
>> (struct A (b c))
>>
>> (struct B (e f) #:transparent)
>>
>> (require (for-syntax racket/struct-info))
>> (define-syntax (get-field-names stx)
>>   (syntax-case stx ()
>> [(_ sym)
>>  #`(quote
>> #,(struct-field-info-list
>>(syntax-local-value #'sym)))
>>   ]))
>>
>> ;; These let me see the field names
>> (get-field-names A)
>> ;; Returns '(c b)
>> (get-field-names B)
>> ;; Returns '(f e)
>>
>> ;;
>> https://stackoverflow.com/questions/20076868/how-to-know-whether-a-racket-variable-is-defined-or-not
>> (define-syntax (defined? stx)
>>   (syntax-case stx ()
>> [(_ id)
>>  (with-syntax ([v (identifier-binding #'id)])
>>#''v)]))
>>
>> (define-syntax (proc-names stx)
>>   (syntax-case stx ()
>> [(_ sym)
>>  (let ([names (map (λ (s)
>>  (string->symbol
>>   (format "~a-~a" (syntax-e #'sym) s)))
>>(struct-field-info-list
>> (syntax-local-value #'sym))
>>)])
>>#`(quote #,names))]))
>>
>> ;; This...
>> (proc-names A)
>> ;; Returns '(A-c A-b)
>>
>> (define-syntax (names-exist? stx)
>>   (syntax-case stx ()
>> [(_ sym)
>>  (let ([names (map (λ (s)
>>  (string->symbol
>>   (format "~a-~a" (syntax-e #'sym) s)))
>>(struct-field-info-list
>> (syntax-local-value #'sym))
>>)])
>>#`(andmap (λ (s)
>>(equal? 'lexical s))
>>  (map (λ (s)
>> (defined? s))
>>   (quote #,names)))
>>)]))
>>
>> (names-exist? A)
>> (names-exist? B)
>>
>>
>> On Sat, Oct 30, 2021 at 10:33 PM Brian Beckman 
>> wrote:
>>
>>> Here are some of my latest (failed) experiments:
>>>
>>> #lang racket
>>>
>>> (require (for-syntax racket/struct-info))
>>> (require racket/pretty)
>>>
>>> (struct foo (a b) #:transparent)
>>>
>>> (displayln `("a foo object is transparent: I can see inside: \n
>>> (struct->vector (foo 1 2)) ~~> "
>>>  ,(struct->vector (foo 1 2
>>>
>>> (displayln `("syntax object is opaque I can't see inside: \n
>>> (struct->vector #'foo) ~~> "
>>>  ,(struct->vector #'foo)))
>>>
>>> ;;; Why do two copies of the syntax display? (One copy
>>> ;;; is a side-effect. The other is a result).
>>>
>>> ;;; At expansion time, I can get some graphics in Dr-Racket for
>>> ;;; definition of foo, but I cannot get likewise
>>> ;;; not into the definition of syntax.
>>> (begin-for-syntax
>>>   (displayln
>>>(extract-struct-info
>>> (syntax-local-value
>>>  #'foo  ; #'syntax
>>>
>>> ;;; But the access procedures for #'syntax are known!?!? (I just
>>> ;;; happen to know that there is a 

Re: [racket-users] Adding keybindings to debug

2021-10-30 Thread David Storrs
The menu strings get very fussy, so check that you entered it exactly
right, and do a very simple one to start. That's the usual cause in my
experience.

On Sat, Oct 30, 2021, 7:25 AM Mike Engelhart  wrote:

> On Mac OS I tried adding keyboard shortcuts using the linked Apple support
> document to allow for comment/uncomment bindings in DrRacket and it doesn't
> work (at least on Mac OS Monterey).  One thing I noticed is that if you go
> back to System Preferences->Keyboard->Shortcuts->App Shortcuts and look at
> DrRacket under App Shortcuts, unlike other Mac OS apps in the list, it only
> shows the name DrRacket but doesn't show any of the shortcuts you've added.
>
>
> On Sat, Oct 30, 2021 at 6:37 AM Laurent  wrote:
>
>> On Fri, Oct 29, 2021 at 10:47 PM James Zollinger 
>> wrote:
>>
>>> Thank you both for the thoughtful answers. I will take a look at the
>>> quickscript you sent, Laurent. The mac keyboard shortcut is a great
>>> feature. Makes me wonder about buying a mac again after quite a few years.
>>> (I use debian as my daily driver, at least for development.)
>>
>>
>> Apparently it should be possible to do the same thing for Debian,
>> depending on your window manager, with some caveats:
>>
>> https://askubuntu.com/questions/107849/can-i-assign-custom-keyboard-shortcuts-for-menu-items-in-applications
>>
>>
>>> If anyone out there knows how to deal with context menus
>>> programmatically, please share.
>>>
>>
>> The code of the debug-tool should be changed to make these reachable from
>> the outside with a define/public. Somewhere around here:
>>
>> https://github.com/racket/drracket/blob/b74dc3bc65b4843db0c2b381161fa9e8d85d230d/drracket/gui-debugger/debug-tool.rkt#L375
>> but it's a little intricate because a set of specialized menu items are
>> created after right-clicking when in debug mode.
>>
>> Another possibility would be to simulate the mouse clicks, but that seems
>> rather hacky and error-prone.
>>
>> --
>> 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/CABNTSaGiZ%2BbZirkyrtTScbVg5EK4reJw-JtoK3%2BTh5%3DCW7SiDQ%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/CAGE%3DCnJ7FfvOOkk0_Q2Ch4kinJx%2BM5MEBwPYDcqNSFqLWQxOSQ%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/CAE8gKodhBXn_qntvi5qzQkYwjQnwA_c2uGhHJem-SSL0dmLm8g%40mail.gmail.com.


Re: [racket-users] Adding keybindings to debug

2021-10-28 Thread David Storrs
I don't know if this fills the need but it's a useful thing to know
regardless:  macOS will allow you to add a keyboard shortcut for any menu
item in any application.
https://support.apple.com/guide/mac-help/create-keyboard-shortcuts-for-apps-mchlp2271/mac

On Thu, Oct 28, 2021 at 1:10 PM James Zollinger  wrote:

> I'm a happy user of DrRacket, plowing through the MIT SICP (Structure and
> Interpretation of Computer Programs.) As I'm learning Scheme, I'm spending
> more time than I'd like to admit in the debugger. I'm more used to
> emacs/bash but really liking the DrRacket IDE (using graphical libs to
> display output, for example) and would really like to stick with it, but
> I'm struggling with the keybindings...
>
> I have seen the documentation:
> https://docs.racket-lang.org/drracket/Keyboard_Shortcuts.html
> but I don't see a way to add keyboard shortcuts in the debugger. I'd like
> to add shortcuts for GUI buttons "Go", "Step", "Over", etc. as well as
> context menus "Print return value to console", "Pause at this point", etc.
>
> Any help would be greatly appreciated.
> James
>
> --
> 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/c429d210-7392-4ad3-90db-b1e9edba08b2n%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/CAE8gKoeadmpRi2te0ez-Ey4B1deUYiXrUNJVjedrTWdNVdq8Sw%40mail.gmail.com.


Re: [racket-users] [ANN] Splitflap: generating valid Atom and RSS feeds

2021-10-26 Thread David Storrs
On Mon, Oct 25, 2021 at 10:25 PM 'Joel Dueck' via Racket Users <
racket-users@googlegroups.com> wrote:

>
>
>- Removing dependencies: yes, I see the appeal. I’m really not eager
>to reimplement all the timezone handling and temporal comparison stuff in
>gregor, though.
>
> Joel
>

Having done a fair bit of datetime programming, my suggestion on the best
way to handle it is to not handle it.  Let some purpose-built library such
as gregor do it  instead of trying to roll your own, because datetime math
is a nightmare.


> On Monday, October 25, 2021 at 6:36:30 PM UTC-5 Sage Gerard wrote:
>
>> Thank you for this!!
>>
>> Feedback
>>
>>- I like your podcast-specific entries
>>- The validation logic is refreshing to see
>>- Re: boolean arguments, I'd stick to keyword arguments and ask for
>>any/c, not boolean?, in contracts. That way forms like (and ... (member
>>...)) won't bug users about a non-threatening contract violation, and it's
>>trivial to cast the value yourself.
>>- Unsure what licenses are compatible with Blue Oak. If you want more
>>licensing options re: IANA media type to extension mappings, here are 
>> some.
>>- MIT: https://github.com/mime-types/mime-types-data
>>   - Apache 2.0 (From the horse's mouth):
>>   https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
>>   - CC-BY-SA: Scrape MDN's table using the console on
>>   
>> https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
>>- I normally don't use functions like splitflap-version because I
>>can't assume that a package will define one. I'd use a program that 
>> returns
>>a version of a given package.
>>- Why is language-codes a procedure?
>>- You have a lot of local contract boundaries, so values may get
>>checked more than necessary.
>>- Prefer example.com so you don't have to leak your URLs or make up
>>email addresses that actually go to an inbox.
>>- txexpr, gregor, and web-server dependencies don't look terribly
>>difficult to remove
>>
>> --
> 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/cb2927c7-3d21-41c3-89c7-d6b73a9e53f9n%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/CAE8gKoc93-d6gUXYEhA_L-bM%3DzqWBbu9UG2TtvX-nqTHaKA_jA%40mail.gmail.com.


Re: [racket-users] How to require untrusted module?

2021-10-22 Thread David Storrs
I'd be interested to know this as well.  It sounds like something that
isn't possible in Racket, since it's essentially specifying how a module
can do its job and that requires a level of introspection that I think is
excluded by design.

On Thu, Oct 21, 2021 at 10:37 AM kalime...@gmail.com 
wrote:

> I've read about protect-out and  current-code-inspector, but I still
> cannot understand, how to require a module and forbid it to run protected
> modules.
>
> Something like (require untrusted-foo) (foo-proc) but to forbid foo-proc
> to use ffi/unsafe.
>
> --
> 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/5f10a124-6aeb-4389-8421-92034e93f8a7n%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/CAE8gKoeSCaFwYSQzuqy2QJAxEtffMLbqr4q02_gw76f2JCYDdA%40mail.gmail.com.


Re: [racket-users] hash->list with try-order? (like hash-map)

2021-10-22 Thread David Storrs
On Thu, Oct 21, 2021 at 5:26 AM George Neuner  wrote:

>
> On 10/20/2021 5:53 PM, unlimitedscolobb wrote:
>
>
>
You can get a lot of mileage out of the 'set' datatype, which removes
ordering from the equation, especially since lists will act as sets in a
pinch.  (When you want to improve performance, use 'in-set' and/or
'list->set'.

To see if 2 hashes contain the same set of keys:
>
> (and (= (hash-count hash1) (hash-count hash2))
>  (for/and ([k (in-list (hash-keys hash1))])
>(hash-has-key? hash2 k)))
>

Alternatively:

(set=? (hash-keys hash1) (hash-keys hash2))


; Return an unordered list of the keys that are in hash1 but not in hash2
(set-subtract (hash-keys hash1) (hash-keys hash2))

; Get a new hash consisting of the key/values that are in hash1 but not in
hash2
(for/hash ([k (set-subtract (hash-keys hash1) (hash-keys hash2))])
  (values k (hash-ref hash1 k)))

; Get a ore detailed breakdown:
(require handy)
(define hash1 (for/hash ([k '(a b c d e f g)] [v 10]) (values k v)))
(define hash2 (for/hash ([k '(a b c d e z y)] [v 10]) (values k v)))
(define hash3 (hash-set* hash2 'c 111 'd 184))
(disjunction hash1 hash3)
Result:
(dict-disjunction
 '#hash((c . (2 111)) (d . (3 184))); values that differ between the hashes
 '#hash((f . 5) (g . 6)) ; key/values that exist only in hash1
 '#hash((y . 6) (z . 5)) ; key/values that exist only in hash3
 '#hash((a . 0) (b . 1) (c . 2) (d . 3) (e . 4) (f . 5) (g . 6)) ; hash1
 '#hash((a . 0) (b . 1) (c . 111) (d . 3) (e . 4) (y . 6) (z . 5))) ; hash3


> Unfortunately, there is no variant of "for" that creates mutable hashes.
> But the general form works for anything.
>

If you don't mind inefficiency then handy can be, well, handy:

(define imm-h  (for/hash ([k '(a b c)][v 3]) (values k v)))
(immutable? imm-h)
(immutable? (hash->mutable imm-h))

hash->mutable takes an existing hash, which can be either immutable or
mutable, and adds its key/values to a new mutable hash one by one, then
returns that hash.

The handy module is a bit of a Fibber McGee that really needs to be broken
out.  It's thoroughly documented, but unfortunately only in comments.
Converting that to proper scribble is one of my Copious Free Times projects.

-- 
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/CAE8gKoeZWCPg4yS41L9jPeL7gZzgW1iLusr3xJJYQTsj6491Xg%40mail.gmail.com.


Re: [racket-users] rename-out not working as expected

2021-10-12 Thread David Storrs
Okay, good.  Thanks for the library recommendation; I'll probably use that
in the future where I need to rename/provide multiple things, but given
that there's only one I did this instead in order to avoid having another
dependency:

(provide do-it)
(define do-it (procedure-rename do-something 'do-i))

I suspect I'm reinventing the wheel and that's what static-rename compiles
down to.


On Tue, Oct 12, 2021 at 3:14 PM 'William J. Bowman' via Racket Users <
racket-users@googlegroups.com> wrote:

> I think this is the expected behaviour of `rename-out`; you might want
> this library to change the dynamic displayed name:
>   https://docs.racket-lang.org/static-rename/index.html
>
> --
> William J. Bowman
>
> On Tue, Oct 12, 2021 at 03:07:13PM -0400, David Storrs wrote:
> > ---
> > ; test.rkt
> > #lang racket
> > (define (do-something) "ok")
> > (provide do-something)
> >
> > ; test2.rkt
> > #lang racket
> > (require "test.rkt")
> > (provide (rename-out [do-something do-it]))
> >
> > #lang racket
> > (require "test2.rkt")
> > do-it
> > ---
> >
> > The printed value is # although I was expecting
> > #.  Have I done something wrong or simply misunderstood
> > how rename-out works?
> >
> > --
> > 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/CAE8gKodiRBWPK5MfgYnOi_V%2B%3DwwFzBxtQK1qV2Mj-zPuHEXn9g%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/YWXekUFzaEkaitiB%40williamjbowman.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/CAE8gKodCGGStB5LW-sw8DNDCeR-G4Zt9UxMsbcCs6mAZUiH%3DMw%40mail.gmail.com.


[racket-users] rename-out not working as expected

2021-10-12 Thread David Storrs
---
; test.rkt
#lang racket
(define (do-something) "ok")
(provide do-something)

; test2.rkt
#lang racket
(require "test.rkt")
(provide (rename-out [do-something do-it]))

#lang racket
(require "test2.rkt")
do-it
---

The printed value is # although I was expecting
#.  Have I done something wrong or simply misunderstood
how rename-out works?

-- 
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/CAE8gKodiRBWPK5MfgYnOi_V%2B%3DwwFzBxtQK1qV2Mj-zPuHEXn9g%40mail.gmail.com.


Re: [racket-users] Re: Escape continuations for fussy code

2021-10-01 Thread David Storrs
On Fri, Oct 1, 2021 at 11:58 AM Hendrik Boom  wrote:

> On Fri, Oct 01, 2021 at 02:22:14PM +, Jesse Alama wrote:
> > Hello,
> >
> > Have you ever wished you could do a C-style return in the middle
> > of a block of Racket code? When you're in the heat of things with
> > a complicated problem where input values need a fair amount of
> > multi-stage extraction and validation, using cond quickly pulls
> > code to the right. My procedure is:
> >
> > * cond/case. In each branch:
> > * Define some new values safe in the knowledge of where you are
> > (extract) and perhaps check them, if necessasry (validate)
> > * Make sure you have an else branch.
> > * return to 1 and repeat as many times as necessary.
> >
> > The result:
> >
> > (cond [(foo? x)
> > (define y (bar x))
> > (define z (jazz x y))
> > (cond [(loopy? z)
> > (define a (yowza z))
> > (cond [(string? a)
> > (define b (bonkers a))
> > (cond [(number? (hoop x b))
> > (define ...)]
> > [else
> > (error 'um)])]
> > [else
> > (error 'ugh)])]
> > [else #f])]
> > [else #f])
>
>
I'm presuming that this code should either return #f, return a calculated
value, or raise an exception.  If so, here's a version that runs in plain
racket that I find pretty easy to read.  It has the advantage that the
'return #f' parts aren't way far away from what causes them.

(with-handlers ([false? identity] ; return #f
[any/c  raise])   ; re-raise everything else
  (let* ([x (if (foo? x)
x
(raise #f))]
 [z (jazz x (bar x))]
 [a (if (loopy? z)
(yowza z)
(raise #f))]
 [b (if (string? a)
(bonkers a)
(error 'ugh))])
(if (number? (hoop x b))
'all-good
(error 'um

If instead you want to return the exn that comes from error instead of
re-raising it then you can do that by removing the false? clause from the
with-handlers.  NOTE:  You should re-raise exn:break since otherwise the
user cannot ^C the program.

(with-handlers ([exn:break?  raise]
[any/c   identity])
  ...put the let* code 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAE8gKodxas7jtze%2BttcFA%2BG0ATKUFZD3rhK%2B%3Dn2U1md1zQPJSg%40mail.gmail.com.


Re: [racket-users] Having trouble getting documentation to generate

2021-09-29 Thread David Storrs
Cool, thanks.

On Wed, Sep 29, 2021 at 11:23 AM Matthew Flatt  wrote:

> At Wed, 29 Sep 2021 11:20:47 -0400, David Storrs wrote:
> > On Wed, Sep 29, 2021 at 9:57 AM Matthew Flatt 
> wrote:
> >
> > > At Wed, 29 Sep 2021 02:27:53 +, Philip McGrath wrote:
> > > > I haven't tried `raco setup` to look at its output, but one possible
> > > > improvement would be for whatever code complains about the "invalid
> > > `deps'
> > > > specification" to always report the invalid file's path.
> > >
> > > I've pushed that addition.
> > >
> > >
> > Thanks, Matthew.  Is this a "download Racket 8.2" thing or an "update
> from
> > github" thing?
>
> The improvement is only in the GitHub repo right now. So, updating from
> GitHub gets it now, it will also be part of the next round of
> snapshots, and then it will be part of the upcoming v8.3 release.
>
>
> Matthew
>

-- 
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/CAE8gKoegBUGVbfmguydZwaVBWgrNOJWJ3CmxTvShROR4-dpvJw%40mail.gmail.com.


Re: [racket-users] Having trouble getting documentation to generate

2021-09-29 Thread David Storrs
On Wed, Sep 29, 2021 at 9:57 AM Matthew Flatt  wrote:

> At Wed, 29 Sep 2021 02:27:53 +, Philip McGrath wrote:
> > I haven't tried `raco setup` to look at its output, but one possible
> > improvement would be for whatever code complains about the "invalid
> `deps'
> > specification" to always report the invalid file's path.
>
> I've pushed that addition.
>
>
Thanks, Matthew.  Is this a "download Racket 8.2" thing or an "update from
github" thing?

-- 
> 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/20210929075734.246%40sirmail.smtps.cs.utah.edu
> .
>

-- 
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/CAE8gKodObvuRt-j2v9zHf5VdBo-nOWWKZvApQPk4Qir-BBBRkA%40mail.gmail.com.


Re: [racket-users] Having trouble getting documentation to generate

2021-09-28 Thread David Storrs
On Tue, Sep 28, 2021 at 3:30 PM Ben Greenman 
wrote:

> On 9/28/21, David Storrs  wrote:
>
> > Also, any ideas on why the remove fails?
> >
> > $ raco pkg remove try-catch
> > raco pkg remove: invalid `deps' specification
> >   specification: '("base" racket/format racket/string)
> >
> > That is not the deps specification from the info.rkt file so I don't know
> > where it's getting that.
>
> Some package somewhere must have that bad info.rkt file.
>
> A plain "raco setup" might be the quickest way to find the bad one.
> That should print the name of every package as it goes through them.


It did show them right up to the point where it bonked but did not show the
name of the one it bonked on.  Fortunately, since you told me what the
issue was I was able to find it with a simple:

$ find . -name official-racket -prune -o -name info.rkt -exec grep -l
'racket/format' \{} \;

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/CAFUu9R5%3DCL-_wfB52aG82Vg9y%2B9HKpQhxk_dX08ub5Ln948QGQ%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/CAE8gKoevcaM26JaaBYVZCORxsXJXVUO9zZNJYR2UPcH_94Rb8Q%40mail.gmail.com.


[racket-users] [ANN] try-catch - exception handling with dynamic-wind guarantees

2021-09-28 Thread David Storrs
Module name:  try-catch
https://pkgd.racket-lang.org/pkgn/package/try-catch

Lisp stereotypically has a problem that it's super easy to write your own
code so the library ecosystem ends up fractured, with multiple options to
do the same thing.  McCarthy forbid that I should break the stereotype, so
here's my entry into the try/catch niche.

> (try [shared (define username "bob")]
   [pre (printf "in pre, prepping to handle ~a.\n" username)]
   [(printf "in body. hello, ~a.\n" username)]
   [post (printf "in post, goodbye ~a.\n" username)]
   [catch (symbol? (printf "the symbol was ~a\n" e))]
   [cleanup (printf "in cleanup, done with ~a." username)])
in pre, prepping to handle bob.
in body. hello, bob.
in post, goodbye bob.
in cleanup, done with bob.


pre/body/post are plugged into a dynamic-wind, meaning that the pre clause
is executed before body whenever control enters the body (either normally
or through a continuation jump or etc) and the post clause is executed
whenever control leaves the body.

The catch clause contains subclauses of (predicate handler-expr) that get
fed into a with-handlers, except the handler-exprs are wrapped in a (lambda
(e) ...) in order to reduce boilerplate.  The value 'e' is available to the
handler-expr.

The shared clause does setup before the pre/body are called and the code in
that clause is visible to all subsequent clauses.

The cleanup clause is run iff the body exits without error.

See the documentation for full details and examples.  (Note that the
package server is not currently admitting that there is documentation but
there will be when you install it.)

Competing options:

try  (Typed Racket):  https://pkgs.racket-lang.org/package/try
try-catch-finally and try-catch-finally-lib:
https://pkgs.racket-lang.org/package/try-catch-finally and
https://pkgs.racket-lang.org/package/try-catch-finally-lib
try-catch-match: https://pkgs.racket-lang.org/package/try-catch-match
try-make-sarna-happy:
https://pkgs.racket-lang.org/package/try-make-sarna-happy

My motivation for writing this instead of submitting pull requests was in
part syntactic (the other libraries all use (catch ...) for each of the
catch clauses and I dispreferred the redundancy of typing 'catch' over and
over) and in part because I wanted the 'shared' and 'cleanup' phases which
would have required greater changes to their macros than I was comfortable
submitting.

-- 
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/CAE8gKoeQXhhKatZzjMePd_qbqiNPBOeyX%3DsMqisAVateOBVKrQ%40mail.gmail.com.


Re: [racket-users] [ANN] fmt: a Racket code formatter

2021-09-28 Thread David Storrs
This is very cool, Sorawee.  Thank you for sharing.

On Tue, Sep 28, 2021 at 2:03 PM Sorawee Porncharoenwase <
sorawee.pw...@gmail.com> wrote:

> Announcing the pre-alpha version of fmt, a Racket code formatter. Code
> formatter is a tool that reformats your code so that it conforms to a style
> consistently.
>
>- Source: https://github.com/sorawee/fmt/
>- Documentation and demo: https://docs.racket-lang.org/fmt/
>
> As a part of this work, I implemented Jean-Philippe Bernady’s non greedy
> pretty printer  (ICFP’17) and
> extended it so that it is practical for actual use.
>
>- Source: https://github.com/sorawee/pprint-compact/
>- Documentation and demo: https://docs.racket-lang.org/pprint-compact/
>
> Hope you find these useful, and let me know if you have any feedback.
>
> Sorawee (Oak)
>
> --
> 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/CADcueguOiOBK4vE3kCfvWYkb2Eaz-JfM5_Yd%3DGct-6umSUEG6w%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/CAE8gKodp-Cy3L%2BX%3DH8fSYZwtqLPVFZJVESRp_nOeV7VY_OM8zQ%40mail.gmail.com.


Re: [racket-users] Having trouble getting documentation to generate

2021-09-28 Thread David Storrs
*fists of rage*

I'm glad it worked for you, and that it works for me if I repeat your
steps.  I have no idea why it wasn't working given that I was using the
local copy of the git repository that is the source of what's on github.
Argh.

Regardless, thank you very much for your help.  I've fixed the (for-label
try-catch), removed the test-more dependency, pushed it to github, and told
the package server to rescan.  It says it will do that 1 minute from now,
so hopefully it'll be good to go at that point.  I think documentation only
gets generated once per day though, right?


Also, any ideas on why the remove fails?

$ raco pkg remove try-catch
raco pkg remove: invalid `deps' specification
  specification: '("base" racket/format racket/string)

That is not the deps specification from the info.rkt file so I don't know
where it's getting that.


On Tue, Sep 28, 2021 at 1:36 PM Ben Greenman 
wrote:

> On 9/28/21, David Storrs  wrote:
> > Summary:  Documentation for a new module is not being generated when I
> > would expect it to be and when I do it manually it ends up not linking
> > basic Racket items.  I've done a lot of searching to figure it out and
> > would appreciate some help.
>
> I cloned the try-catch repo (744f217), ran raco pkg install, and got a
> nicely-rendered document. Log attached.
>
> The only problem I saw is that `try` isn't linked. You can fix that by
> adding a `(require (for-label try-catch))`.
>
>
> > Long version:
> >
> > I published a module a few days ago called try-catch.  I have an announce
> > email written up for it but I was waiting for the documentation to
> generate
> > before sending.  It still hasn't generated so today I investigated.
> >
> > First thing I did was make sure that raco was using the local copy for
> > everything:
> >
> > $ raco pkg remove try-catch
> > raco pkg remove: invalid `deps' specification
> >   specification: '("base" racket/format racket/string)
> >
> > Weird.
> >
> > $ raco setup --check-pkg-deps try-catch
> > [...lots of stuff, no problems reported]
> >
> > Okay, whatever.
> >
> > $ raco pkg remove --force try-catch
> >
> > Turn off the WiFi to be certain I don't get the package server version.
> >
> > $ raco pkg install ./try-catch
> >
> > Succeeds, claims that it is building the documentation, does not actually
> > do so.  Ditto when I try
> >
> > $ raco setup try-catch
> >
> > When I manually run
> >
> > $ cd try-catch/scribblings/ && scribble try-catch.scbl
> >
> > I get the try-catch.html file as expected but racket/base functions such
> as
> > with-handlers are not properly linked -- i.e. they appear in blue with a
> > red line under them and are not links.
>
> That's normal. Scribble needs a few command-line flags to know where
> to look for cross references (xrefs). I don't know the right flags
> offhand.
>
>
> > I do not get any missing dependencies when I run
> >
> > My info.rkt file and try-catch.scrbl are both based on those from other
> > modules I have that do work correctly.  I've checked the issues that were
> > pointed out to me the last time I had to ask this question, I've been
> > through the Racket documentation and through Beautiful Racket, and still
> > not found the answer.  Any suggestions?
> >
> >
> > ;; The info.rkt file
> > #lang info
> >
> > (define collection "try-catch")
> > (define version "0.1")
> > (define deps '("base"
> >"syntax-classes-lib"))
> >
> > (define scribblings '(("scribblings/try-catch.scrbl" (
> >
> > (define test-omit-paths '())
> > (define build-deps '("racket-doc"
> >  "scribble-lib"
> >  "rackunit-lib"
> >  "sandbox-lib"))
> >
> > ;;--
> > ;;  The top lines from main.rkt to show the require:
> >
> > #lang racket/base
> >
> > (require (for-syntax racket/base
> >  syntax/parse)
> >  racket/function)
> >
> > ;;--
> > ;; A stripped-down version of scribblings/try-catch.scrbl that
> demonstrates
> > the failures
> >
> > #lang scribble/manual
> >
> > @(require (for-label racket)
> >   racket/sandbox
> >   scribble/example)
> >
> > @defmodule[try-catch]
> >
> > @(define eval
> >(call-with-trusted-sandbox-configuration
> > (lambda ()
> >   

[racket-users] Having trouble getting documentation to generate

2021-09-28 Thread David Storrs
Summary:  Documentation for a new module is not being generated when I
would expect it to be and when I do it manually it ends up not linking
basic Racket items.  I've done a lot of searching to figure it out and
would appreciate some help.

Long version:

I published a module a few days ago called try-catch.  I have an announce
email written up for it but I was waiting for the documentation to generate
before sending.  It still hasn't generated so today I investigated.

First thing I did was make sure that raco was using the local copy for
everything:

$ raco pkg remove try-catch
raco pkg remove: invalid `deps' specification
  specification: '("base" racket/format racket/string)

Weird.

$ raco setup --check-pkg-deps try-catch
[...lots of stuff, no problems reported]

Okay, whatever.

$ raco pkg remove --force try-catch

Turn off the WiFi to be certain I don't get the package server version.

$ raco pkg install ./try-catch

Succeeds, claims that it is building the documentation, does not actually
do so.  Ditto when I try

$ raco setup try-catch

When I manually run

$ cd try-catch/scribblings/ && scribble try-catch.scbl

I get the try-catch.html file as expected but racket/base functions such as
with-handlers are not properly linked -- i.e. they appear in blue with a
red line under them and are not links.

I do not get any missing dependencies when I run

My info.rkt file and try-catch.scrbl are both based on those from other
modules I have that do work correctly.  I've checked the issues that were
pointed out to me the last time I had to ask this question, I've been
through the Racket documentation and through Beautiful Racket, and still
not found the answer.  Any suggestions?


;; The info.rkt file
#lang info

(define collection "try-catch")
(define version "0.1")
(define deps '("base"
   "syntax-classes-lib"))

(define scribblings '(("scribblings/try-catch.scrbl" (

(define test-omit-paths '())
(define build-deps '("racket-doc"
 "scribble-lib"
 "rackunit-lib"
 "sandbox-lib"))

;;--
;;  The top lines from main.rkt to show the require:

#lang racket/base

(require (for-syntax racket/base
 syntax/parse)
 racket/function)

;;--
;; A stripped-down version of scribblings/try-catch.scrbl that demonstrates
the failures

#lang scribble/manual

@(require (for-label racket)
  racket/sandbox
  scribble/example)

@defmodule[try-catch]

@(define eval
   (call-with-trusted-sandbox-configuration
(lambda ()
  (parameterize ([sandbox-output 'string]
 [sandbox-error-output 'string]
 [sandbox-memory-limit 50])
(make-evaluator 'racket)

@itemlist[
@item{@racket[with-handlers], @racket[~a], @racketmodname[syntax-parse]}
]

@examples[
  #:eval eval
  #:label #f

(require try-catch)
(define err (defatalize (raise-arguments-error 'foo "failed")))
err
(try [(displayln "ok")])
]

-- 
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/CAE8gKoforSuxKVGwj2E_T-_HhLafaFipRGqERh6QUvyn6%2B9MUg%40mail.gmail.com.


Re: [racket-users] Strange readline/racket-mode behavior

2021-09-24 Thread David Storrs
The dev team will have to answer your actual question, but I thought I
might offer a more compact solution that incorporates the fix you mentioned:

(define (yn #:read-one-char? [read-one-char? #f])
  (display "y/n: ")
  (flush-output (current-output-port))
  (define func (if read-one-char? read-char read-line))
  (match (list (func) (func))
[(list _ (or #\y #\Y "y" "Y")) #t]
[_ #f]))

On Fri, Sep 24, 2021 at 3:01 PM Winston Weinert  wrote:

> Hey everyone,
>
> I was working on a procedure to prompt the user for confirmation and found
> something a bit strange - it did not appear to read for input when usingt
> "racket -i" or in the Emacs Racket REPL buffer.  Here is the code:
>
> (define (yn #:read-one-char? [read-one-char? #f])
>   (display "y/n: ")
>   (flush-output (current-output-port))
>   (if read-one-char?
>   (match (read-char)
> [(or #\y #\Y) #t]
> [m #f])
>   (match (read-line)
> [(or "y" "Y") #t]
> [m #f])))
>
> Regardless if I use read-char or read-line and type y or Y, the behavior
> seeims
> similar, each of the match's second clause is followed because (read-char)
> returns #\newline whereas read-line returns "" (empty string).
>
> I mentioned this strange behavior on the Libera chat and got an
> enlightening
> response from tonyg outlining what is happening:
>
> > at the repl, if you type "(read-char)" and press enter, the reader sees
> ( r e
> > a d - c h a r ) NEWLINE. When it gets to the close-parenthesis, it
> executes
> > the expression, which reads the NEWLINE character and returns. Similar
> for
> > read-line, where it sees NEWLINE and returns an empty line
> >
> > try typing (list (read-line) (read-line))
>
> I can confirm tonyg's solution works.  The (list (read-char) (read-char))
> also
> appears to work, though one always has to type a final newline to send the
> line-buffered input.
>
> The behavior feels very surprising and took me a bit of time to figure out,
> even then I didn't really understand it so I had to ask for help.  Can this
> behavior be changed in a future release?  Is a reasonable request or could
> this
> break a lot of code?  If this could break stuff, is it worth doing
> changing it
> anyway, so the behavior is less surprising?  I hope to understand if it's
> agreeable to make a PR for this change before investing the time.
>
> Keep on Racketing!
>
> Winston Weinert
> winny.tech
>
> --
> 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/20210924190134.mjxttwqtgeunjbus%40ml1.net
> .
>

-- 
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/CAE8gKoeXrgNa%2BAkUgbX4sBi77y7wPM0AhRLvrwVfrtKTAyaPCQ%40mail.gmail.com.


Re: [racket-users] What is the correct name for non-list parenthesized forms?

2021-09-24 Thread David Storrs
On Fri, Sep 24, 2021 at 2:37 PM John Clements 
wrote:

> I think I wouldn’t say “accepts”; I usually reserve this term for
> functions, but that’s a minor quibble.
>
> I think I would call these “clauses”, as in
>
> “With-handlers allows the user to specify exception-handling clauses. Each
> one includes two parts: a predicate, indicating whether blah blah blah, and
> a handler, which is called blah blah blah.”
>
> No?
>
> John
>

That seems reasonable.  Thanks, John.



Offtopic question for someone else:  Jay, are you related to Lisp-inventory
John McCarthy?

-- 
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/CAE8gKocbqx7n7uTjAypSMQoQcFjFfaOD%2BKp93m5mf8iQ3fd%2B7g%40mail.gmail.com.


Re: [racket-users] What is the correct name for non-list parenthesized forms?

2021-09-24 Thread David Storrs
On Fri, Sep 24, 2021 at 1:49 PM Jay McCarthy  wrote:

> I think the word you're looking for is "syntax". Many people think that
> languages like Racket "don't have syntax" or "have uniform syntax", but
> this is an example of how that is incorrect. Each macro has its own unique
> syntax and this is an example of how `let` has a unique syntax where `(`
> does _not_ mean "apply a function" or "apply a macro".
>
> As a poor analogy, many human languages have a wide set of phonemes and
> you combine those in certain rules (like you can't have 27 consonant sounds
> in a row) and then use them in wider situations that we call grammar. I
> like to think that languages like C has lots of phonemes and little
> grammar, because there are lots of rules about how to form "C words" but
> basically no rules for how to form "C sentences", because there's a lot of
> uniformity in how expressions and statements combine. In contrast,
> languages like Racket have very few phonemes (this is what I think people
> mean why they say "there is no syntax") but many varied rules (in fact,
> arbitrary, because macros can customize them) for combining those smaller
> units.
>

So there's no specific term for this structure?  I was looking for a
standardized way to say something like "with-handlers accepts a group of
two-element groups where each subgroup consists of a predicate and an
action."

>
> Jay
>
> --
> Jay McCarthy
> Associate Professor @ CS @ UMass Lowell
> http://jeapostrophe.github.io
> Vincit qui se vincit.
>
>
> On Fri, Sep 24, 2021 at 1:25 PM David Storrs 
> wrote:
>
>> Racket has a number of forms that include what look like lists of lists
>> but are not.  For example:  (let ((foo 7) (bar 8)) ...)
>>
>> What would the '(foo 7)' and '(bar 8)' elements be called?  Groups, maybe?
>>
>> --
>> 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/CAE8gKodX800fK45c_dyVFCNB-AKmYmK26DxC42ZRDVHdzJ2Q7g%40mail.gmail.com
>> <https://groups.google.com/d/msgid/racket-users/CAE8gKodX800fK45c_dyVFCNB-AKmYmK26DxC42ZRDVHdzJ2Q7g%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
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/CAE8gKoeM6YYgpj-4Ey%2BoSSKRS%2BfMch3d0GDu85f9mwHmtxwVig%40mail.gmail.com.


Re: [racket-users] What is the correct name for non-list parenthesized forms?

2021-09-24 Thread David Storrs
On Fri, Sep 24, 2021 at 1:40 PM Sorawee Porncharoenwase <
sorawee.pw...@gmail.com> wrote:

> It's usually called "binding pair". See also
> https://docs.racket-lang.org/syntax/stxparse-intro.html which defines a
> syntax class describing the said structure.
>

Okay, but what about in (with-handlers ((symbol? (lambda (e) (displayln
e  ...)?  That's an association between two things but not a binding
pair.  Also, sorry, I should have been clearer up front by giving more than
the one example.


> On Fri, Sep 24, 2021 at 10:25 AM David Storrs 
> wrote:
>
>> Racket has a number of forms that include what look like lists of lists
>> but are not.  For example:  (let ((foo 7) (bar 8)) ...)
>>
>> What would the '(foo 7)' and '(bar 8)' elements be called?  Groups, maybe?
>>
>> --
>> 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/CAE8gKodX800fK45c_dyVFCNB-AKmYmK26DxC42ZRDVHdzJ2Q7g%40mail.gmail.com
>> <https://groups.google.com/d/msgid/racket-users/CAE8gKodX800fK45c_dyVFCNB-AKmYmK26DxC42ZRDVHdzJ2Q7g%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
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/CAE8gKocWRCn_EJuuD5ZSGXfUEOz8OgV9s6dZt4NsHgWGUBhCgg%40mail.gmail.com.


[racket-users] What is the correct name for non-list parenthesized forms?

2021-09-24 Thread David Storrs
Racket has a number of forms that include what look like lists of lists but
are not.  For example:  (let ((foo 7) (bar 8)) ...)

What would the '(foo 7)' and '(bar 8)' elements be called?  Groups, maybe?

-- 
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/CAE8gKodX800fK45c_dyVFCNB-AKmYmK26DxC42ZRDVHdzJ2Q7g%40mail.gmail.com.


Re: [racket-users] Is it possible to capture a the value of a variable inside a macro?

2021-09-17 Thread David Storrs
Additional thought and self-plug:  My struct-plus-plus module creates
structures with full reflection information available, including field
names, contracts, and wrappers.  It also supports type checking, data
normalization, default values, and automatically provides both keyword
constructors and dotted accessors for clarifying field names.  It doesn't
support inheritance but it would make it easy to do many of the things I
think you might be interested in.
https://docs.racket-lang.org/struct-plus-plus/index.html

On Fri, Sep 17, 2021 at 3:08 PM David Storrs  wrote:

>
> NB:  You did a 'reply' to Sorawee instead of to the list as a whole, and
> also the same for the email I sent.  Probably good to 'reply all' so that
> the list gets the full context.
>
> Sorawee offered some good advice on how to do the things you're asking
> about and asked relevant questions.  I'm wondering about the macro level:
>
> A)  What exactly are you trying to do, because I think I've got it but I'm
> still fuzzy.
> B)  Why are you trying to do it?
> C) Is there a simpler / more Racket-ish way to do it?
>
> On Thu, Sep 16, 2021 at 2:12 PM Dimaugh Silvestris <
>> dimaughsilvest...@gmail.com> wrote:
>>
>>> Sorry, I haven't posted the full macro because it's long and makes use
>>> of several other functions, but I'll try to summarize what it does:
>>>
>>> Short summary: I'm trying to have a macro (mymacro oldname newname
>>> (fields ...)) that accesses oldname-foo, which contains a list of symbols,
>>> and then define a function that takes (cons oldname-foo (fields ...))
>>> formated as identifiers as arguments. Or at least to get the length of
>>> oldname-foo and name them whatever.
>>>
>>> Full explanation: using make-struct-type I'm building a different struct
>>> system I call cards, where structs can be defined as a function call, which
>>> will be their constructor, and they are printed as the constructor function
>>> call that would generate them. So, for instance, we can do:
>>>
>>
> I notice that you're using make-struct-type instead of struct -- is that
> intentional or is there some specific feature you want?  I suspect I'm
> about to get a more experienced person telling me that I've missed
> something, but to the best of my knowledge struct is the more modern
> version and can do everything that make-struct-type can do but cleaner.
>
> As to the printing as a constructor call:  putting the #:prefab option on
> a struct will allow you to print it in a reversible form that can be called
> in order to generate the struct again, but it makes explicit all the values
> that go in instead of hiding them away as defaults or etc.  For example:
>
> #lang racket
>
> (struct person (name age) #:prefab)
>
> (person 'bob 17)
>
> (with-output-to-file
>   "/tmp/struct-demo"
>   #:exists 'replace
>   (thunk
>(display (person 'fred 18
>
> (with-input-from-file
>   "/tmp/struct-demo"
>   (thunk (read)))
>
> (with-input-from-file
>   "/tmp/struct-demo"
>   (thunk (person-name (read
>
>
>
> Output:
>
> '#s(person bob 17)
> '#s(person fred 18)
> 'fred
>
> Obviously, reading code directly from a file is a bad plan, but the same
> would work from any appropriate port and I'm using a file because it's
> easy.  The point is that I was able to write it into a port (in this case a
> file port) such that it produced a format that represented the constructor
> call and then read it back into an actual struct that I could use accessors
> on etc.  One disadvantage is that you can't attach properties to a prefab
> struct but that might or might not be relevant to you.
>
>
> > (card (hola a b #:c c))
>>> > (hola 1 2 #:c 3)
>>> (hola 1 2 #:c 3)
>>> or
>>> > (card (ciao a [b 3]))
>>> > (ciao 7)
>>> (ciao 7)
>>> > (ciao 7 4)
>>> (ciao 7 4)
>>>
>>> or even
>>>
>>> > (card (line . xs))
>>> > (line 1 2 3 4 5 6 7 8 9)
>>> (line 1 2 3 4 5 6 7 8 9)
>>>
>>> Also the names of the fields are stored in *-fields
>>> (this is the abc-foo of the above example), so *hola-fields contains '(a b
>>> #:c c).
>>> So far this is working perfectly, but I don't have inheritance. So when
>>> I create a card that inherits from a previous card, I need to access its
>>> *-fields to define a new function containing both the parent
>>> and the son fields. That is, I'm trying to get this behavior:
>>> > (card (hola a #:b b))
>>> > (card hola (ciao c))  ;;; should e

Re: [racket-users] Is it possible to capture a the value of a variable inside a macro?

2021-09-17 Thread David Storrs
NB:  You did a 'reply' to Sorawee instead of to the list as a whole, and
also the same for the email I sent.  Probably good to 'reply all' so that
the list gets the full context.

Sorawee offered some good advice on how to do the things you're asking
about and asked relevant questions.  I'm wondering about the macro level:

A)  What exactly are you trying to do, because I think I've got it but I'm
still fuzzy.
B)  Why are you trying to do it?
C) Is there a simpler / more Racket-ish way to do it?

On Thu, Sep 16, 2021 at 2:12 PM Dimaugh Silvestris <
> dimaughsilvest...@gmail.com> wrote:
>
>> Sorry, I haven't posted the full macro because it's long and makes use of
>> several other functions, but I'll try to summarize what it does:
>>
>> Short summary: I'm trying to have a macro (mymacro oldname newname
>> (fields ...)) that accesses oldname-foo, which contains a list of symbols,
>> and then define a function that takes (cons oldname-foo (fields ...))
>> formated as identifiers as arguments. Or at least to get the length of
>> oldname-foo and name them whatever.
>>
>> Full explanation: using make-struct-type I'm building a different struct
>> system I call cards, where structs can be defined as a function call, which
>> will be their constructor, and they are printed as the constructor function
>> call that would generate them. So, for instance, we can do:
>>
>
I notice that you're using make-struct-type instead of struct -- is that
intentional or is there some specific feature you want?  I suspect I'm
about to get a more experienced person telling me that I've missed
something, but to the best of my knowledge struct is the more modern
version and can do everything that make-struct-type can do but cleaner.

As to the printing as a constructor call:  putting the #:prefab option on a
struct will allow you to print it in a reversible form that can be called
in order to generate the struct again, but it makes explicit all the values
that go in instead of hiding them away as defaults or etc.  For example:

#lang racket

(struct person (name age) #:prefab)

(person 'bob 17)

(with-output-to-file
  "/tmp/struct-demo"
  #:exists 'replace
  (thunk
   (display (person 'fred 18

(with-input-from-file
  "/tmp/struct-demo"
  (thunk (read)))

(with-input-from-file
  "/tmp/struct-demo"
  (thunk (person-name (read



Output:

'#s(person bob 17)
'#s(person fred 18)
'fred

Obviously, reading code directly from a file is a bad plan, but the same
would work from any appropriate port and I'm using a file because it's
easy.  The point is that I was able to write it into a port (in this case a
file port) such that it produced a format that represented the constructor
call and then read it back into an actual struct that I could use accessors
on etc.  One disadvantage is that you can't attach properties to a prefab
struct but that might or might not be relevant to you.


> (card (hola a b #:c c))
>> > (hola 1 2 #:c 3)
>> (hola 1 2 #:c 3)
>> or
>> > (card (ciao a [b 3]))
>> > (ciao 7)
>> (ciao 7)
>> > (ciao 7 4)
>> (ciao 7 4)
>>
>> or even
>>
>> > (card (line . xs))
>> > (line 1 2 3 4 5 6 7 8 9)
>> (line 1 2 3 4 5 6 7 8 9)
>>
>> Also the names of the fields are stored in *-fields
>> (this is the abc-foo of the above example), so *hola-fields contains '(a b
>> #:c c).
>> So far this is working perfectly, but I don't have inheritance. So when I
>> create a card that inherits from a previous card, I need to access its
>> *-fields to define a new function containing both the parent
>> and the son fields. That is, I'm trying to get this behavior:
>> > (card (hola a #:b b))
>> > (card hola (ciao c))  ;;; should expand to (define (ciao a #:b b c)
>> ...), among other things
>> > (ciao 1 #:b 2 3)
>> (ciao 1 #:b 2 3)
>>
>
How are you going to handle the situation where a parent and child struct
have a field with the same name?  This is entirely legit:

#lang racket

(struct person (name age) #:prefab) ; age is years since birth

(struct employee person (age) #:prefab) ; age is years since hiring


(define bob (employee 'bob 17 3))
bob
(employee-age bob)
(person-age bob)

Output:

'#s((employee person 2) bob 17 3)
3
17


Going back to the earlier question:  What is it you are ultimately trying
to accomplish at a high level?  i.e. Not "generate a lot of struct types
and field data" but something like "store information about a hierarchical
structure of  in a persistent way so that it is recoverable across
server restarts."



>> On Thu, 16 Sept 2021 at 22:35, Sorawee Porncharoenwase <
>> sorawee.pw...@gmail.com> wrote:
>>
>>> In general, it would be helpful to provide an example of the macro use,
>>> so that we know what you want to do. If it doesn't work, it would be
>>> helpful to provide the buggy program and an error message so that we can
>>> help with the issue that you are encountering.
>>>
>>> From my guess, you have a variable named abc-foo somewhere, and with
>>> this macro, you wish to define a function named abc that 

Re: [racket-users] Is it possible to capture a the value of a variable inside a macro?

2021-09-16 Thread David Storrs
Sorawee answered your immediate question, but I figured I'd offer a pointer
to Fear of Macros in case you haven't seen it:
https://www.greghendershott.com/fear-of-macros/  It helped me a lot when I
was trying to get my head around macros.  Also, I got a lot of value from
reading through the code of
https://pkgs.racket-lang.org/package/struct-update

On Thu, Sep 16, 2021 at 4:21 PM Dimaugh Silvestris <
dimaughsilvest...@gmail.com> wrote:

> (sorry if I'm asking too many questions about macros lately, I'm learning
> about them but I keep running into scenarios I can't find documentation for)
>
> I'm trying to capture the value of a variable whose identifier I can only
> get with format-id, inside a with-syntax.
> Something like this pseudocode (imagine name-foo contains a list of
> symbols):
> (define-syntax (my-macro stx)
>   (syntax-case stx ()
> ((_ name other-args ...)
>  (with-syntax* ((varname (format-id #'name "~a-foo" #'name))
> (varval (cons (datum->syntax #'varname) (datum->syntax
> #'(other-args ...)
>#'(define name (λ varval (print varval)))
>
>
> Which of course doesn't work. I understand this might have to do with how
> macros work at an earlier phase than runtime, so is it impossible?
>
> --
> 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/CAN4YmRF%3Do3NsXOvK2fvUDeYL_jfA9r946%3D%3DguoGb_%3DKyS%3Dm%2Bxw%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/CAE8gKod53kD4ZFyxmatP4qx%2BvSKqrnT-if7PCD4MWxA7Tva3-Q%40mail.gmail.com.


[racket-users] Set logging (or env variables generally) in racket-mode

2021-09-14 Thread David Storrs
racket-mode is terrifically useful, and my only issue with it is that it
doesn't show logging messages.   Is there a way to make it do that?

-- 
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/CAE8gKoffYSXVGYEyLB3ekn%2Br1LPcQBJipnr2XMF9pipGdSdTWg%40mail.gmail.com.


Re: [racket-users] Re: Is there a way to format keys/values like raise-arguments-error

2021-09-10 Thread David Storrs
On Fri, Sep 10, 2021 at 1:33 PM kamist...@gmail.com 
wrote:

> I like the apply max instead of foldl, quite a bit easier.
>
> Instead of `(format "\t~a" (~a (~a k #:width width) v #:separator "\t"))`
> I prefer one of these:
> (~a "\t" (~a k #:width width) "\t" v)
> (~a #:separator "\t" "" (~a k #:width width) v)
>

Fine.  If you want to be all efficient and readable, go right ahead.

Thanks, applied.  :>


> --
> 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/d652f06d-81ed-4a5c-983c-d1716f838a38n%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/CAE8gKod3k_wBfCtVPe9daOg%3DXkKvq-ZAcYDcCdHqq-%3DUBQ%3DFbg%40mail.gmail.com.


Re: [racket-users] Is there a way to format keys/values like raise-arguments-error

2021-09-10 Thread David Storrs
Thank you, Laurent.  That's a cool package; I think it would work well to
generate tables suitable for org-mode spreadsheets.  I could even pull data
from a sqlite DB, giving me power and portability without needing an
internet connection or a full heavyweight spreadsheet app.

On Thu, Sep 9, 2021 at 5:26 PM Laurent  wrote:

> Maybe take a look at the text-table package.
>
> On Wed, 8 Sep 2021, 14:41 David Storrs,  wrote:
>
>> raise-arguments-errors produces neatly stacked key/value pairs with
>> whitespace arranged such that values line up even when keys are of
>> different lengths.  Is there an easy way to get that for something that is
>> not an error?  I've been through both The Printer and the
>> raise-arguments-error sections in the Reference and can't find anything.
>>
>> For example:
>>
>> (doit "x" 1 "foo" 2 "super" 3)
>>
>> Returns the string "x 1\nfoo   2\super 3"
>>
>>
>>
>>
>> --
>> 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/CAE8gKod_s8EhQPW9uG7P02%3D8Kmpqf2Uw%3DKLORWD%3DwmFrxnGkWA%40mail.gmail.com
>> <https://groups.google.com/d/msgid/racket-users/CAE8gKod_s8EhQPW9uG7P02%3D8Kmpqf2Uw%3DKLORWD%3DwmFrxnGkWA%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
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/CAE8gKodAzS2-FCt_KxoP-StFvxQpHBnYd1VCwb6sh9n0rPKS-g%40mail.gmail.com.


Re: [racket-users] Re: Is there a way to format keys/values like raise-arguments-error

2021-09-10 Thread David Storrs
Wow, thank you Simon.  That was above and beyond.

I should have thought of ~a to start with.  With your pointers I came up
with a less flexible solution that is sufficient to the current issue:


#lang racket/base
(require racket/format
 racket/string)

(define my-keys   '("bacon" "eggs" "pancakes"))
(define my-vals   '("turkey" "whites" "blueberry"))

(define (make-str keys vals)
  (define width (apply max (map string-length keys)))
  (string-join
   (for/list ([k keys]
  [v vals])
 (format "\t~a" (~a (~a k #:width width) v #:separator "\t")))
   "\n"))

(displayln (make-str my-keys my-vals))


On Thu, Sep 9, 2021 at 4:11 PM kamist...@gmail.com 
wrote:

> I am not really aware of a function that does this you could try digging
> into the implementation of raise-arguments-error,
> usually I roll my own implementation depending on what I really want to
> output.
> racket/format and its ~a, ~v, etc. have a lot of useful optional keyword
> arguments like #:align #:pad-string #:width etc.
>
> This isn't totally what you want, but maybe it has something that is
> useful to you.
> This or similar code is what I have used sometimes:
>
> #lang racket
>
> (define current-prefix-length (make-parameter 0))
> (define (prefixln #:prefix [prefix ""]
>   #:align  [align 'left]
>   . message)
>   (displayln (apply ~a (list* (~a prefix #:width (current-prefix-length)
> #:align align)
>   message
>
> (define-syntax-rule (with-indent body ...)
>   (parameterize ([current-prefix-length (+ (current-prefix-length) 2)])
> body ...))
>
> (define (example-func1)
>   (prefixln "start of example func1")
>   (with-indent
> (example-func2))
>   (prefixln "end of example func1"))
>
> (define (example-func2)
>   (prefixln "start of example func2")
>   (prefixln "end of example func2"))
>
>
> (module+ main
>
>   (displayln "Hello checkout these values:")
>   (define example-values
> (hash 'foo 123
>   'this-is-a-long-key "some value"
>   'blabla #f
>   "cake" "is a lie"))
>
>   ;; ugly oneliner to calculate prefix width
>   (current-prefix-length (+ 2 (foldl max 0 (map (compose1 string-length
> ~a) (hash-keys example-values)
>
>   (for ([(k v) (in-hash example-values)]) ;; probably sorting or assoc
> list would make sense too...
> (prefixln #:prefix (~a k ": ") #:align 'right
>   v))
>
>   (current-prefix-length 0)
>   (displayln "")
>   (displayln "indentation through multiple nested calls:")
>   (with-indent
> (example-func1)))
>
> If you use a current-prefix-string parameter instead you can create other
> interesting things like lines indented with indentation level indicators,
> etc.:
> indent0
> | indent1
> | | indent2
> | indent1
> indent0
>
> But I am getting too off-topic...
>
> Simon
>
> david@gmail.com schrieb am Mittwoch, 8. September 2021 um 15:41:56
> UTC+2:
>
>> raise-arguments-errors produces neatly stacked key/value pairs with
>> whitespace arranged such that values line up even when keys are of
>> different lengths.  Is there an easy way to get that for something that is
>> not an error?  I've been through both The Printer and the
>> raise-arguments-error sections in the Reference and can't find anything.
>>
>> For example:
>>
>> (doit "x" 1 "foo" 2 "super" 3)
>>
>> Returns the string "x 1\nfoo   2\super 3"
>>
>>
>>
>>
>> --
> 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/de65e4a2-7cd3-4347-949f-d8a1f457961en%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/CAE8gKoc5md1TUFJHmRb6%3DNTUJ%2BCzCMLDaQV5poUR64YCAo9bbg%40mail.gmail.com.


[racket-users] [module announce] in-out-logged

2021-09-08 Thread David Storrs
Package: https://pkgs.racket-lang.org/package/in-out-logged

Wraps a chunk of code in "entering" and "leaving" log messages, returns the
value(s) produced by the code.

Example:

Keyword arguments are all optional. #:to and #:at may appear in either
order but #:with must come last if it is present.

(define-logger foo)
(define (on-complete op . args)
(log-foo-debug "in on-complete")
(apply op args))

(in/out-logged ("on-complete"
  #:to foo-logger
  #:at 'debug ; NB:  This is the default so it could be
omitted
  "time" (current-inexact-milliseconds))
 (on-complete + 1 2 5))

  (in/out-logged ("values"
  #:at 'error   ; NB:  Goes to (current-logger) since #:to
not given.  Has 'error priority
  #:with "time is: ~a, username is: ~a."
(current-inexact-milliseconds) 'bob)
 (values 1 2))

Produces:

foo: entering on-complete. args:
time  1631134220582.874
foo: in on-complete
foo: leaving on-complete. args:
time  1631134220582.874
8

entering values. time is: 1631134385090.149, username is: bob.
leaving values. time is: 1631134385090.161, username is: bob.
1
2

With thanks to Martin DeMello and Sorawee Porncharoenwase for suggestions
on syntax and functionality.


TODO:  Better formatting of the arguments.






(in/out-logged ("name" #:to foo-logger #:at 'info #:with "args are: ~a ~a" '
arg1 'arg2) code ...)

-- 
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/CAE8gKocMnqcQVw31SQjUqaSoFmZS9TDSy1%2ByT9yf25Py6VmN%3DQ%40mail.gmail.com.


Re: [racket-users] Why does syntax-parser work here but not syntax-parse?

2021-09-08 Thread David Storrs
*headdesk headdesk headdesk headdesk headdesk*

Thank you.

On Wed, Sep 8, 2021 at 2:02 PM Stephen Chang  wrote:

> > shouldn't the entire parenthesized expression be given to the macro
> processor and then replaced with something valid before being rejected?
>
> That would be true if you're defining a macro, i.e. if you use
> `define-syntax` instead of `define`.
>
> >
> > --
> > 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/CAE8gKofDYFY8AYb2Lyh7CQXx1i01w8jm4DVcMrJL%3DQYHX9SsRQ%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/CAE8gKoez09TZCYy7BkiMZ4O1G8rYs4M7vdgGbnJpm0uEJ%3Dr-Kw%40mail.gmail.com.


[racket-users] Why does syntax-parser work here but not syntax-parse?

2021-09-08 Thread David Storrs
This is from the documentation and it obviously works:

(define parser1
  (syntax-parser
[((~alt (~once (~seq #:a x) #:name "#:a keyword")
(~optional (~seq #:b y) #:name "#:b keyword")
(~seq #:c z)) ...)
 'ok]))
(parser1 #'(#:a 1))

When run it yields 'ok.

If I change it to this, it fails and I don't understand why:

(define (parser2 stx)
  (syntax-parse stx
[(parser2 ((~alt (~once (~seq #:a x) #:name "#:a keyword")
 (~optional (~seq #:b y) #:name "#:b keyword")
 (~seq #:c z)) ...))
 #''ok]))
(parser2 (#:a 1))

This yields:
[...source location...] #%datum: keyword misused as an expression
;   at: #:a


I can see that (#:a 1) is not valid under the default parser since #:a is
not valid for initial position but shouldn't the entire parenthesized
expression be given to the macro processor and then replaced with something
valid before being rejected?

-- 
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/CAE8gKofDYFY8AYb2Lyh7CQXx1i01w8jm4DVcMrJL%3DQYHX9SsRQ%40mail.gmail.com.


[racket-users] Is there a way to format keys/values like raise-arguments-error

2021-09-08 Thread David Storrs
raise-arguments-errors produces neatly stacked key/value pairs with
whitespace arranged such that values line up even when keys are of
different lengths.  Is there an easy way to get that for something that is
not an error?  I've been through both The Printer and the
raise-arguments-error sections in the Reference and can't find anything.

For example:

(doit "x" 1 "foo" 2 "super" 3)

Returns the string "x 1\nfoo   2\super 3"

-- 
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/CAE8gKod_s8EhQPW9uG7P02%3D8Kmpqf2Uw%3DKLORWD%3DwmFrxnGkWA%40mail.gmail.com.


Re: [racket-users] New module log-bracketed; should probably be something else

2021-09-03 Thread David Storrs
On Thu, Sep 2, 2021 at 5:32 PM Sorawee Porncharoenwase <
sorawee.pw...@gmail.com> wrote:

> Thoughts:
>
>- Perhaps the logger should be optional. The default value would be
>(current-logger).
>- The event name (like on-complete) could also be optional. The
>default would be the source location of the macro invocation site
>- Instead of “time: ~a”, I think it would be nice to support many
>“pairs”, which are formatted like raise-arguments-error.
>
> Example:
>
> (define (on-complete x)
>   (log-test-debug "I'm in on-complete")
>   x)
>
> (with-log ()
>   1)
>
> (with-log (#:logger test-debug
>#:msg "on-complete"
>["time" (current-seconds)])
>   (on-complete (person 'bob)))
>
> would output:
>
> test: entering test.rkt:5:1
> test: exiting test.rkt:5:1
> result: 1
> 1
> test: entering on-complete
> time: 123
> test: I'm in on-complete
> test: exiting on-complete
> time: 124
> result: (person 'bob)
> (person 'bob)
>
>
>
First of all, thank you.  I like the idea of the event name being optional
and the logger defaulting but I'm not keen on the syntax.  It's very
verbose for something that might occasionally be wrapped around a single
line of code. The raise-arguments-error formatting would be a nice default
but I prefer to give the option to use a format string if you want
something different.


> On Thu, Sep 2, 2021 at 2:06 PM Martin DeMello 
> wrote:
>
>> I do like the second form better, especially since the actual code being
>> run is not obscured by simply being the last argument to a long log
>> function.
>>
>
Cool.  I'll move towards that.


>> martin
>>
>> On Thu, Sep 2, 2021 at 1:55 PM David Storrs 
>> wrote:
>>
>>> I often find that for debugging I want to see a log message saying "I'm
>>> about to do X" followed by X followed by "I'm done with X" and I want it to
>>> return the result of X.
>>>
>>> I wrote this macro and posted it to the package server:
>>> https://pkgs.racket-lang.org/package/log-bracketed
>>>
>>> In retrospect, the syntax is bad and I should change it.  Can anyone
>>> suggest something better?
>>>
>>>   (define (on-complete x) (log-test-debug "entering on-complete") x)
>>>   (struct person (name) #:transparent)
>>>
>>>   (log-bracketed test-debug "on-complete" "time: ~a" (current-seconds) 
>>> (on-complete (person 'bob)))
>>>   (log-bracketed test-debug "on-complete" "" "no user-specified logging 
>>> information")
>>>
>>> Spits out:
>>>
>>>
>>> test: about to on-complete. time: 1630611613
>>> test: entering on-complete
>>> test: after on-complete. time: 1630611613. result: (person 'bob)
>>> (person 'bob)
>>> test: about to on-complete
>>> test: after on-complete. result: "no user-specified logging information"
>>> "no user-specified logging information"
>>>
>>>
>>> The problem is that this looks like it's a simple logging message when
>>> in fact it's real code that should not be ignored.  I'm trying to think of
>>> a better way to do it...maybe something like this?:
>>>
>>>   (with-bracketing-logs ([test-debug "on-complete" "time: ~a" 
>>> (current-seconds)])
>>>
>>>  (on-complete (person 'bob))
>>>
>>>
>>>
>>> --
>>> 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/CAE8gKocZha-NpiFAAKT1c8QTG3MDFRnvxCD4T0P269EncZW3KQ%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/racket-users/CAE8gKocZha-NpiFAAKT1c8QTG3MDFRnvxCD4T0P269EncZW3KQ%40mail.gmail.com?utm_medium=email_source=footer>
>>> .
>>>
>> --
>> 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/CAFrFfuEqt1NVjE2Ft1JVArvWnKUBvK7jPVoLqPhYCd-dB00A3Q%40mail.gmail.com
>> <https://groups.google.com/d/msgid/racket-users/CAFrFfuEqt1NVjE2Ft1JVArvWnKUBvK7jPVoLqPhYCd-dB00A3Q%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
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/CAE8gKod16Tto8j3U_F1JffJujFQozxmxmdoSLhyw95gQkh%2BiVw%40mail.gmail.com.


[racket-users] New module log-bracketed; should probably be something else

2021-09-02 Thread David Storrs
I often find that for debugging I want to see a log message saying "I'm
about to do X" followed by X followed by "I'm done with X" and I want it to
return the result of X.

I wrote this macro and posted it to the package server:
https://pkgs.racket-lang.org/package/log-bracketed

In retrospect, the syntax is bad and I should change it.  Can anyone
suggest something better?

  (define (on-complete x) (log-test-debug "entering on-complete") x)
  (struct person (name) #:transparent)

  (log-bracketed test-debug "on-complete" "time: ~a" (current-seconds)
(on-complete (person 'bob)))
  (log-bracketed test-debug "on-complete" "" "no user-specified
logging information")

Spits out:


test: about to on-complete. time: 1630611613
test: entering on-complete
test: after on-complete. time: 1630611613. result: (person 'bob)
(person 'bob)
test: about to on-complete
test: after on-complete. result: "no user-specified logging information"
"no user-specified logging information"


The problem is that this looks like it's a simple logging message when in
fact it's real code that should not be ignored.  I'm trying to think of a
better way to do it...maybe something like this?:

  (with-bracketing-logs ([test-debug "on-complete" "time: ~a"
(current-seconds)])

 (on-complete (person 'bob))

-- 
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/CAE8gKocZha-NpiFAAKT1c8QTG3MDFRnvxCD4T0P269EncZW3KQ%40mail.gmail.com.


[racket-users] Changing log destination from the environment

2021-08-25 Thread David Storrs
I've always used loggers in their default form, where they send to the
terminal, and then I use tee if I want it to go to a file as well.  That's
easy and effective but there's got to be a better way.  Two questions:

1) Is there a way to change logger destinations from the environment such
that modifying the code isn't necessary?   (e.g. send it to a file instead
of the terminal)

2) Is there a way to make a log message go to multiple destinations at the
same time? (e.g. to the terminal and to a file)

My sense is that Racket is explicitly designed to not allow redirecting the
logs at runtime, since the documentation makes a point of saying that it
sends to the process's *original* error port.  Is that right?

It looks like I could get around this by manually creating log receivers,
syncing them in a separate thread, and manually processing the messages
that get pumped to them.  I could even have it poll the environment to
check for destination CLI arguments. That seems pretty kludgy and I thought
I'd ask for a better solution.


I've been through the command line section and the logging section of the
docs and am stumped.  If there's a relevant section of the FM that I missed
please point me.

https://docs.racket-lang.org/reference/running-sa.html#%28part._mz-cmdline%29
https://docs.racket-lang.org/reference/logging.html

-- 
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/CAE8gKodh2A2gE%3DbJ_DDJdRMN2B8LLnn%2BEHKPxU7oyM1XbS7TwA%40mail.gmail.com.


Re: [racket-users] [ANN] Introducing "social" contracts

2021-08-16 Thread David Storrs
Hi Siddhartha,

Will this package handle ->* and ->i, either now or in the future?

On Sat, Aug 14, 2021 at 1:40 PM Siddhartha Kasivajhula 
wrote:

> Fellow Scheming Racketeers,
> When you've written a function that takes an integer and returns another
> one, you may write a contract for it as (-> integer? integer?). I want to
> tell you about the social-contract
>  package which
> allows you to write it as (self-map/c integer?) instead.
>
> Why would the latter form be preferable? It isn't much less to type. But,
> as we'll see, it is composable and it exploits the phrase structure of a
> contract specification. Consider:
>
> (-> (-> integer? integer? integer?) (-> integer? integer? integer?)))
>
> With social-contract, this would be expressed as:
>
> (self-map/c (binary-composition/c integer?))
>
> With a little familiarity, this tells you a lot, and saves you the trouble
> of parsing the low level contract specification in order to understand what
> this function does.
>
> And how about this:
> (-> (-> any/c boolean?) sequence? sequence?)
>
> This becomes simply:
> filter/c
>
>
> *Who decides what "self map," "composition," and "filter" mean?*
> We all do! In principle. The contracts available right now correspond to
> well-known mathematical or programming ideas, but they could be anything at
> all that we find to be common and useful. The "social" idea here is that,
> through issues raised and discussed
>  on the source
> repo, we collectively agree on the forms and variations of useful high
> level contracts.
>
>
> *But wouldn't it be tedious to learn the social contract forms?*
> On the contrary, it just might be fun. The package ships with C3PO, a
> handy contract migration assistant that already knows both the Racket
> contract DSL as well as the social contract forms, so you can provide
> contracts you've already written and it will translate them into high-level
> social contract representations. This can be useful for learning the new
> forms in an interactive way, and can also greatly reduce the time it would
> take to migrate any existing contracts you may have.
>
> Incidentally, C3PO is a "reverse compiler" implemented using parser
> combinators (megaparsack
> ). It is "reverse"
> in that it translates low-level contract specifications into high-level
> ones, and may be a curiosity in its own right. You can learn more about it
> here
> 
> and see its source here
> 
> .
>
> Enjoy,
> -Sid
>
> --
> 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/CACQBWFnUiaRZrO6jaGtOdyr1HxF%2BXn8aSovjC_VAaMHQtuHFxQ%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/CAE8gKofRhtH6LRMQLMMSpdWtAdysrw7mjqB%2BnMG%2BHoEy48MtLg%40mail.gmail.com.


[racket-users] Is anyone looking to hire a junior web developer?

2021-07-10 Thread David Storrs
I have an acquaintance who has been learning web development as a way out
of the poverty trap she's stuck in.  I don't have personal experience with
her skills but I can say that she's highly motivated and will work hard.
If anyone has a Python or web-development job opening, could you drop me a
link?

-- 
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/CAE8gKofEZtaF%3DB4i%2B9MeWavgoirdRyyUgy3MXZeA_VLX-CQ%3Dsw%40mail.gmail.com.


Re: [racket-users] Moving a function into a different `place?`

2021-07-01 Thread David Storrs
On Thu, Jul 1, 2021 at 2:42 PM Sam Tobin-Hochstadt 
wrote:

> Your "only remaining idea" is what I'd recommend for telling another
> place what function to run (that's how dynamic-place works in the
> first place). But your [details] sounds worrying. I just tested on my
> machine and it didn't happen for me, and I don't think it's supposed
> to happen on other platforms either.
>

*frowns*
*goes and checks*

My mistake, I misremembered the details.  It only happens if you want the
platform-specific version of the dialog.  If you use the Racket version
it's fine but then your interface doesn't match what the user is expecting.

https://groups.google.com/g/racket-users/c/wexYxYYU7GE/m/3zXxn6NoAwAJ?pli=1


> Sam
>
> On Thu, Jul 1, 2021 at 2:36 PM David Storrs 
> wrote:
> >
> > What is the best way to pass a function into a child `place`?
> >
> > I've got a server function that accepts a dispatch function as one of
> its arguments and I need to be able to run the server in a separate `place`
> (in the dynamic-place sense) because it's part of a GUI application.
> [details]
> >
> > My initial thought was to start the place and then use
> place-channel-(put/get) to move the run-time argument from the main place
> over into the child.  I immediately realized that doesn't work because
> functions are not `place-message-allowed?` values.  Next I thought about
> using a parameter, but parameters in a child place are set to their
> *initial* values, not their run-time values.  (Barring a few special cases.)
> >
> > I considered passing a string or symbol list and then eval'ing it in the
> child place.  I immediately rejected this idea and told my brain that it
> was being bad and it got no cookies.
> >
> > At this point my only remaining idea is to place-channel-(put/get) a
> module name that can be dynamic-required in the child place in order to get
> the dispatch function.  Is there a better way?
> >
> >
> > [details]
> > The Racket GUI library has an issue where e.g. launching an 'Open File'
> dialog will freeze all of Racket until the user closes the dialog.  This
> can cause the server to time out.  Since it's all of Racket that's being
> frozen and not just the current thread it's necessary to put the server
> code into an entirely different `place`.
> >
> > --
> > 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/CAE8gKoemyTeoP2GW5-_h6rGxW_1YcfyCQfHSs9ee98h3pRE4mg%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/CAE8gKoemg5DpdSx-iGcmu-5huM19zCtrdZXkjHHE2JhK7aGpXg%40mail.gmail.com.


[racket-users] Moving a function into a different `place?`

2021-07-01 Thread David Storrs
What is the best way to pass a function into a child `place`?

I've got a server function that accepts a dispatch function as one of its
arguments and I need to be able to run the server in a separate `place` (in
the dynamic-place sense) because it's part of a GUI application. [details]

My initial thought was to start the place and then use
place-channel-(put/get) to move the run-time argument from the main place
over into the child.  I immediately realized that doesn't work because
functions are not `place-message-allowed?` values.  Next I thought about
using a parameter, but parameters in a child place are set to their
*initial* values, not their run-time values.  (Barring a few special cases.)

I considered passing a string or symbol list and then eval'ing it in the
child place.  I immediately rejected this idea and told my brain that it
was being bad and it got no cookies.

At this point my only remaining idea is to place-channel-(put/get) a module
name that can be dynamic-required in the child place in order to get the
dispatch function.  Is there a better way?


[details]
The Racket GUI library has an issue where e.g. launching an 'Open File'
dialog will freeze all of Racket until the user closes the dialog.  This
can cause the server to time out.  Since it's all of Racket that's being
frozen and not just the current thread it's necessary to put the server
code into an entirely different `place`.

-- 
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/CAE8gKoemyTeoP2GW5-_h6rGxW_1YcfyCQfHSs9ee98h3pRE4mg%40mail.gmail.com.


Re: [racket-users] invalid memory error from parameter with contracted guard

2021-06-24 Thread David Storrs
Got it. Thank you.

On Thu, Jun 24, 2021 at 10:04 AM Matthew Flatt  wrote:

> Procedures with contracts are usually implemented by structs that have
> `prop:procedure`. Those applicable structs are not procedures from Chez
> Scheme's perspective. So, in the "Rumble" layer that bridges Chez
> Scheme and Racket, care must be taken to use a special `|#%app|` form
> instead of direct function application when the function to call might
> be from the Racket layer and implemented as an applicable struct.
>
> Parameters are implemented in the Rumble layer, but applying a
> parameter's guard procedure didn't use `|#%app|` as it should have. The
> repair was to add `|#%app|`.
>
> At Thu, 24 Jun 2021 09:55:39 -0400, David Storrs wrote:
> > Great! You're the best, Matt.  What was the issue, if it's simple enough
> to
> > explain?
> >
> > On Wed, Jun 23, 2021, 11:53 PM Matthew Flatt  wrote:
> >
> > > Hi David,
> > >
> > > Thanks for the report! This is fixed for the next release and in
> > > the current snapshots.
> > >
> > > The repair was commit
> > >
> > >   cb959879de21406571fb0127ded88c54e171c0eb
> > >
> > > See also https://github.com/racket/racket/issues/3865
> > >
> > >
> > > Matthew
> > >
> > >
> > > At Wed, 23 Jun 2021 22:30:53 -0400, David Storrs wrote:
> > > > I'm seeing an "invalid memory reference.  Some debugging context
> lost"
> > > > error when using a parameter that has a guard function AND the guard
> > > > function is user-defined AND the guard function has a contract on it.
> > > What
> > > > is the right place to file this aside from the list?
> > > >
> > > > Demonstration:
> > > >
> > > > #lang racket/base
> > > >
> > > > (require racket/contract)
> > > >
> > > > (define p1 (make-parameter ""))
> > > > (displayln "before set p1")
> > > > (p1 "ok")
> > > > (displayln "before read p1")
> > > > (p1)
> > > >
> > > > (define/contract p2 (parameter/c string?) (make-parameter ""))
> > > > (displayln "before set p2")
> > > > (p2 "ok")
> > > > (displayln "before read p2")
> > > > (p2)
> > > >
> > > >
> > > > (define/contract p3 (parameter/c string? integer?) (make-parameter
> "7"
> > > > string->number ))
> > > > (displayln "before set p3")
> > > > (p3 "8")
> > > > (displayln "before read p3")
> > > > (p3)
> > > >
> > > > (define (uncontracted-string->number v)
> > > >   (string->number v))
> > > >
> > > > (define/contract (contracted-string->number v)
> > > >   (-> string? number?)
> > > >   (string->number v))
> > > >
> > > > (define/contract p4  (parameter/c string? integer?)  (make-parameter
> "7"
> > > > uncontracted-string->number))
> > > > (displayln "before set p4")
> > > > (p4 "8")
> > > > (displayln "before read p4")
> > > > (p4)
> > > >
> > > > (define/contract p5  (parameter/c string? integer?)  (make-parameter
> "7"
> > > > contracted-string->number))
> > > > (displayln "before set p5")
> > > > (p5 "8")
> > > > (displayln "before read p5")
> > > > (p5) ; invalid memory reference.  Some debugging context lost
> > > >
> > > > --
> > > > 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/CAE8gKoegLAOk9mHjKRNAJniki_6DHXJe
> > > > OKcjPFa75vPkJqemjw%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/CAE8gKodFEaCLcviocskdiQ1iac7icxqt5sKyBD89Tafw%3DRZn6Q%40mail.gmail.com.


Re: [racket-users] invalid memory error from parameter with contracted guard

2021-06-24 Thread David Storrs
Great! You're the best, Matt.  What was the issue, if it's simple enough to
explain?

On Wed, Jun 23, 2021, 11:53 PM Matthew Flatt  wrote:

> Hi David,
>
> Thanks for the report! This is fixed for the next release and in
> the current snapshots.
>
> The repair was commit
>
>   cb959879de21406571fb0127ded88c54e171c0eb
>
> See also https://github.com/racket/racket/issues/3865
>
>
> Matthew
>
>
> At Wed, 23 Jun 2021 22:30:53 -0400, David Storrs wrote:
> > I'm seeing an "invalid memory reference.  Some debugging context lost"
> > error when using a parameter that has a guard function AND the guard
> > function is user-defined AND the guard function has a contract on it.
> What
> > is the right place to file this aside from the list?
> >
> > Demonstration:
> >
> > #lang racket/base
> >
> > (require racket/contract)
> >
> > (define p1 (make-parameter ""))
> > (displayln "before set p1")
> > (p1 "ok")
> > (displayln "before read p1")
> > (p1)
> >
> > (define/contract p2 (parameter/c string?) (make-parameter ""))
> > (displayln "before set p2")
> > (p2 "ok")
> > (displayln "before read p2")
> > (p2)
> >
> >
> > (define/contract p3 (parameter/c string? integer?) (make-parameter "7"
> > string->number ))
> > (displayln "before set p3")
> > (p3 "8")
> > (displayln "before read p3")
> > (p3)
> >
> > (define (uncontracted-string->number v)
> >   (string->number v))
> >
> > (define/contract (contracted-string->number v)
> >   (-> string? number?)
> >   (string->number v))
> >
> > (define/contract p4  (parameter/c string? integer?)  (make-parameter "7"
> > uncontracted-string->number))
> > (displayln "before set p4")
> > (p4 "8")
> > (displayln "before read p4")
> > (p4)
> >
> > (define/contract p5  (parameter/c string? integer?)  (make-parameter "7"
> > contracted-string->number))
> > (displayln "before set p5")
> > (p5 "8")
> > (displayln "before read p5")
> > (p5) ; invalid memory reference.  Some debugging context lost
> >
> > --
> > 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/CAE8gKoegLAOk9mHjKRNAJniki_6DHXJe
> > OKcjPFa75vPkJqemjw%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/CAE8gKofUXLECAnJmCBOSfZ3UZP70PzZBKNwcV3U9DBv4jkQ5LA%40mail.gmail.com.


[racket-users] invalid memory error from parameter with contracted guard

2021-06-23 Thread David Storrs
I'm seeing an "invalid memory reference.  Some debugging context lost"
error when using a parameter that has a guard function AND the guard
function is user-defined AND the guard function has a contract on it.  What
is the right place to file this aside from the list?

Demonstration:

#lang racket/base

(require racket/contract)

(define p1 (make-parameter ""))
(displayln "before set p1")
(p1 "ok")
(displayln "before read p1")
(p1)

(define/contract p2 (parameter/c string?) (make-parameter ""))
(displayln "before set p2")
(p2 "ok")
(displayln "before read p2")
(p2)


(define/contract p3 (parameter/c string? integer?) (make-parameter "7"
string->number ))
(displayln "before set p3")
(p3 "8")
(displayln "before read p3")
(p3)

(define (uncontracted-string->number v)
  (string->number v))

(define/contract (contracted-string->number v)
  (-> string? number?)
  (string->number v))

(define/contract p4  (parameter/c string? integer?)  (make-parameter "7"
uncontracted-string->number))
(displayln "before set p4")
(p4 "8")
(displayln "before read p4")
(p4)

(define/contract p5  (parameter/c string? integer?)  (make-parameter "7"
contracted-string->number))
(displayln "before set p5")
(p5 "8")
(displayln "before read p5")
(p5) ; invalid memory reference.  Some debugging context lost

-- 
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/CAE8gKoegLAOk9mHjKRNAJniki_6DHXJeOKcjPFa75vPkJqemjw%40mail.gmail.com.


Re: [racket-users] Why would writing to a pipe fail?

2021-06-16 Thread David Storrs
In case anyone else runs into this issue and is worried about their code
blocking forever, here's a version that will time out.  The only change is
the use of sync/timeout and value-evt.
https://docs.racket-lang.org/value-evt/index.html

(require value-evt)
(define bstr (make-shared-bytes 509 5))
(define rx-pipe-size 16777216)
(define-values (rx-in rx-out) (make-pipe rx-pipe-size))

(define (room-in-rx-pipe? bstr)
  (define avail (- rx-pipe-size (pipe-content-length rx-out)))
  (displayln (format "avail: ~a" avail))
  (<= (bytes-length bstr) avail))

(displayln (format "space available? ~a " (room-in-rx-pipe? bstr)))
(displayln (format "pipe content length: ~a" (pipe-content-length rx-out)))

; if write-bytes takes more than 0.5 seconds then it will be interrupted
and num-bytes-written will end up being #f
; wrapping the write-bytes expressing in a thunk is important because we
don't want it to be evaluated before the sync
(define num-bytes-written (sync/timeout 0.5 (value-evt (thunk (write-bytes
bstr rx-out)
(unless (eq? num-bytes-written (bytes-length bstr))
  (displayln (format "rx buffer overflow. pipe content length: ~a, written
~a, expected ~a"
 (pipe-content-length rx-out) num-bytes-written
(bytes-length bstr

(displayln "done")

 output
avail: 16777216
space available? #t
pipe content length: 0
done
test.r

On Wed, Jun 16, 2021 at 4:13 PM David Storrs  wrote:

> Got it. Thanks.
>
> On Wed, Jun 16, 2021 at 3:45 PM Matthew Flatt  wrote:
>
>> At Wed, 16 Jun 2021 14:25:40 -0400, George Neuner wrote:
>> > It looks like the problem
>> > is that "flush" is not defined ...
>>
>> Yes, "returns without blocking after writing as many bytes as it can
>> immediately flush" is vague, and more or less intentionally so. The
>> intent it really "writes as much as is convenient, with the guarantee
>> that anything written is completely flushed". Maybe the documentation
>> should be revised to say something more like that.
>>
>> There's not intended to be a guarantee that as much is written as could
>> possibly make sense by `write-bytes-avail`. Implementation issues may
>> make writing additional bytes inconvenient enough that it doesn't
>> happen, for example, even if more is always written on the next
>> `write-bytes-avail*` call. Also, ports are meant to be used in
>> concurrent settings where the notion "as much as possible" is prone to
>> race conditions.
>>
>> The Racket BC and CS pipe implementations find different things
>> convenient, in this sense, and that's why they behave differently in
>> the example. (That is, it's not really about the Racket version, but CS
>> versus BC.)
>>
>> So, the intent is that you use `write-bytes` when you want to wait
>> until all bytes are written (maybe because you know that will be soon
>> enough, for whatever reason). But when using `write-bytes-avail`, be
>> prepared for a fraction of the bytes to be written, for whatever
>> reason.
>>
>

-- 
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/CAE8gKocHjnCsVYcp7ubEvH_P7nX0xMzv4NmfyByeFZvSowtj2A%40mail.gmail.com.


Re: [racket-users] Why would writing to a pipe fail?

2021-06-16 Thread David Storrs
Got it. Thanks.

On Wed, Jun 16, 2021 at 3:45 PM Matthew Flatt  wrote:

> At Wed, 16 Jun 2021 14:25:40 -0400, George Neuner wrote:
> > It looks like the problem
> > is that "flush" is not defined ...
>
> Yes, "returns without blocking after writing as many bytes as it can
> immediately flush" is vague, and more or less intentionally so. The
> intent it really "writes as much as is convenient, with the guarantee
> that anything written is completely flushed". Maybe the documentation
> should be revised to say something more like that.
>
> There's not intended to be a guarantee that as much is written as could
> possibly make sense by `write-bytes-avail`. Implementation issues may
> make writing additional bytes inconvenient enough that it doesn't
> happen, for example, even if more is always written on the next
> `write-bytes-avail*` call. Also, ports are meant to be used in
> concurrent settings where the notion "as much as possible" is prone to
> race conditions.
>
> The Racket BC and CS pipe implementations find different things
> convenient, in this sense, and that's why they behave differently in
> the example. (That is, it's not really about the Racket version, but CS
> versus BC.)
>
> So, the intent is that you use `write-bytes` when you want to wait
> until all bytes are written (maybe because you know that will be soon
> enough, for whatever reason). But when using `write-bytes-avail`, be
> prepared for a fraction of the bytes to be written, for whatever
> reason.
>

-- 
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/CAE8gKofs0PPHs9mUmSgudMZsqaUEOpV6CCzRB7D3kwZyFXartg%40mail.gmail.com.


Re: [racket-users] Why would writing to a pipe fail?

2021-06-16 Thread David Storrs
For the record, it doesn't work in 8.1 either.

On Wed, Jun 16, 2021 at 2:44 PM David Storrs  wrote:

>
>
> On Wed, Jun 16, 2021 at 2:25 PM George Neuner 
> wrote:
>
>>
>> On 6/16/2021 2:16 PM, David Storrs wrote:
>>
>> Damn.  Sorry, I posted out of sync versions of code and output.  This is
>> correct:
>>
>> (define bstr (make-shared-bytes 509 5))
>> (define rx-pipe-size 16777216)
>> (define-values (rx-in rx-out) (make-pipe rx-pipe-size))
>>
>> (define (room-in-rx-pipe? bstr)
>>   (define avail (- rx-pipe-size (pipe-content-length rx-out)))
>>   (displayln (format "avail: ~a" avail))
>>   (<= (bytes-length bstr) avail))
>>
>> (displayln (format "space available? ~a " (room-in-rx-pipe? bstr)))
>> (displayln (format "pipe content length: ~a" (pipe-content-length
>> rx-out)))
>> (define num-bytes-written (write-bytes-avail* bstr rx-out))
>> (unless (eq? num-bytes-written (bytes-length bstr))
>>   (displayln (format "rx buffer overflow. pipe content length: ~a,
>> written ~a, expected ~a"
>>  (pipe-content-length rx-out) num-bytes-written
>> (bytes-length bstr
>>
>> (displayln "done")
>>
>>  output:
>>
>> avail: 16777216
>> space available? #t
>> pipe content length: 0
>> rx buffer overflow. pipe content length: 15, written 15, expected 509
>> done
>>
>>
>>
>> That's ok ... my analysis was wrong anyhow.   It looks like the problem
>> is that "flush" is not defined ... or simply doesn't work ... on Racket's
>> pipes.  *write-bytes-avail*  et al  depend on flush and so they won't
>> work.  *write-bytes*  works fine, but will block if you fill the pipe.
>>
>> This looks like something for the development team.
>>
>> George
>>
>
> Yup!  That was the problem.  It works fine in 7.6, not in 8.0.  Thanks,
> George.
>
>> --
>> 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/4836be0b-f785-9394-b18f-f5228970ba44%40comcast.net
>> <https://groups.google.com/d/msgid/racket-users/4836be0b-f785-9394-b18f-f5228970ba44%40comcast.net?utm_medium=email_source=footer>
>> .
>>
>

-- 
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/CAE8gKodbSU2xJip-87zwfEhercsbVmjyt2AHfhcsEF%3Dq3wK0KQ%40mail.gmail.com.


Re: [racket-users] Why would writing to a pipe fail?

2021-06-16 Thread David Storrs
On Wed, Jun 16, 2021 at 2:25 PM George Neuner  wrote:

>
> On 6/16/2021 2:16 PM, David Storrs wrote:
>
> Damn.  Sorry, I posted out of sync versions of code and output.  This is
> correct:
>
> (define bstr (make-shared-bytes 509 5))
> (define rx-pipe-size 16777216)
> (define-values (rx-in rx-out) (make-pipe rx-pipe-size))
>
> (define (room-in-rx-pipe? bstr)
>   (define avail (- rx-pipe-size (pipe-content-length rx-out)))
>   (displayln (format "avail: ~a" avail))
>   (<= (bytes-length bstr) avail))
>
> (displayln (format "space available? ~a " (room-in-rx-pipe? bstr)))
> (displayln (format "pipe content length: ~a" (pipe-content-length rx-out)))
> (define num-bytes-written (write-bytes-avail* bstr rx-out))
> (unless (eq? num-bytes-written (bytes-length bstr))
>   (displayln (format "rx buffer overflow. pipe content length: ~a, written
> ~a, expected ~a"
>  (pipe-content-length rx-out) num-bytes-written
> (bytes-length bstr
>
> (displayln "done")
>
>  output:
>
> avail: 16777216
> space available? #t
> pipe content length: 0
> rx buffer overflow. pipe content length: 15, written 15, expected 509
> done
>
>
>
> That's ok ... my analysis was wrong anyhow.   It looks like the problem is
> that "flush" is not defined ... or simply doesn't work ... on Racket's
> pipes.  *write-bytes-avail*  et al  depend on flush and so they won't
> work.  *write-bytes*  works fine, but will block if you fill the pipe.
>
> This looks like something for the development team.
>
> George
>

Yup!  That was the problem.  It works fine in 7.6, not in 8.0.  Thanks,
George.

> --
> 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/4836be0b-f785-9394-b18f-f5228970ba44%40comcast.net
> <https://groups.google.com/d/msgid/racket-users/4836be0b-f785-9394-b18f-f5228970ba44%40comcast.net?utm_medium=email_source=footer>
> .
>

-- 
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/CAE8gKod26a2KC2FXyK2u9dADvQFhB90irnoGuwTi9RKXiFq34g%40mail.gmail.com.


Re: [racket-users] Why would writing to a pipe fail?

2021-06-16 Thread David Storrs
Damn.  Sorry, I posted out of sync versions of code and output.  This is
correct:

(define bstr (make-shared-bytes 509 5))
(define rx-pipe-size 16777216)
(define-values (rx-in rx-out) (make-pipe rx-pipe-size))

(define (room-in-rx-pipe? bstr)
  (define avail (- rx-pipe-size (pipe-content-length rx-out)))
  (displayln (format "avail: ~a" avail))
  (<= (bytes-length bstr) avail))

(displayln (format "space available? ~a " (room-in-rx-pipe? bstr)))
(displayln (format "pipe content length: ~a" (pipe-content-length rx-out)))
(define num-bytes-written (write-bytes-avail* bstr rx-out))
(unless (eq? num-bytes-written (bytes-length bstr))
  (displayln (format "rx buffer overflow. pipe content length: ~a, written
~a, expected ~a"
 (pipe-content-length rx-out) num-bytes-written
(bytes-length bstr

(displayln "done")

 output:

avail: 16777216
space available? #t
pipe content length: 0
rx buffer overflow. pipe content length: 15, written 15, expected 509
done

On Wed, Jun 16, 2021 at 2:11 PM George Neuner  wrote:

>
> On 6/16/2021 1:19 PM, David Storrs wrote:
>
> I'm getting bytes off the wire and attempting to write them to a port.  I
> have a check in place to verify that the pipe has free space but when I
> attempt to reports that yes, there is space, and then it writes and fails
> regardless and I'm not sure why.  The following is a simplified version of
> the code but it produces the same results as the live version.
>
> I've dug through the docs on write-bytes-avail* and pipes and I'm
> scratching my head.  Any thoughts?
>
> --- code
> #lang racket
> (define bstr (make-shared-bytes 509 5))
> (define rx-pipe-size 16777216)
> (define-values (rx-in rx-out) (make-pipe rx-pipe-size))
>
> (define (room-in-rx-pipe? bstr)
>   (define avail (- rx-pipe-size (pipe-content-length rx-out)))
>   (displayln (format "space available: ~a" avail))
>   (<= (bytes-length bstr) avail))
>
> (displayln (format "space available? ~a " (room-in-rx-pipe? bstr)))
> (define num-bytes-written (write-bytes-avail* bstr rx-out))
> (unless (eq? num-bytes-written (bytes-length bstr))
>   (displayln (format "rx buffer overflow. num-bytes-written ~a, expected
> ~a"
>  num-bytes-written (bytes-length bstr
>
> (displayln "done")
>  /code
>
> The output is:
>
> --- output
> avail: 16777216
> space available? #t
> pipe content length: 0
> rx buffer overflow. pipe content length: 15, written 15, expected 509
> done
> --- /output
>
>
>
> I'm not sure what's going on either, but your output says the pipe
> contains 15 characters/bytes and THAT will cause *write-bytes-avail**  to
> fail ... it fails if there is existing buffered content.  I suspect that it
> will work if you substitute *write-bytes-avail*  (no *)  or have
> something read from the pipe before writing to it.
>
> I've never used Racket's pipes, but this looks very much like a connect
> handshake issue.
>
> George
>
> --
> 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/0619cc74-a15d-a0f2-38b7-09feeebf59c0%40comcast.net
> <https://groups.google.com/d/msgid/racket-users/0619cc74-a15d-a0f2-38b7-09feeebf59c0%40comcast.net?utm_medium=email_source=footer>
> .
>

-- 
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/CAE8gKocz8BkvRc%2BeDhDt0WpOmqzkeEYdoQ9cfacGJhNkXkNugg%40mail.gmail.com.


[racket-users] Why would writing to a pipe fail?

2021-06-16 Thread David Storrs
I'm getting bytes off the wire and attempting to write them to a port.  I
have a check in place to verify that the pipe has free space but when I
attempt to reports that yes, there is space, and then it writes and fails
regardless and I'm not sure why.  The following is a simplified version of
the code but it produces the same results as the live version.

I've dug through the docs on write-bytes-avail* and pipes and I'm
scratching my head.  Any thoughts?

--- code
#lang racket
(define bstr (make-shared-bytes 509 5))
(define rx-pipe-size 16777216)
(define-values (rx-in rx-out) (make-pipe rx-pipe-size))

(define (room-in-rx-pipe? bstr)
  (define avail (- rx-pipe-size (pipe-content-length rx-out)))
  (displayln (format "space available: ~a" avail))
  (<= (bytes-length bstr) avail))

(displayln (format "space available? ~a " (room-in-rx-pipe? bstr)))
(define num-bytes-written (write-bytes-avail* bstr rx-out))
(unless (eq? num-bytes-written (bytes-length bstr))
  (displayln (format "rx buffer overflow. num-bytes-written ~a, expected ~a"
 num-bytes-written (bytes-length bstr

(displayln "done")
 /code

The output is:

--- output
avail: 16777216
space available? #t
pipe content length: 0
rx buffer overflow. pipe content length: 15, written 15, expected 509
done
--- /output

-- 
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/CAE8gKodhx-cZ75-WBb9qcqO9Aotq5ebDCiO6T33x%2BYK_RdCAkw%40mail.gmail.com.


Re: [racket-users] Computed properties for a struct?

2021-06-07 Thread David Storrs
On Fri, Jun 4, 2021 at 6:21 PM flirora  wrote:

> Is there a way to define a struct so that it has a field whose value is
> filled in (instead of passed to the constructor) with a value derived from
> other fields? For example, could you define a struct foo with two
> explicit fields, x and y, plus a field called z whose value is computed
> as (+ x y) (yes, simple, but imagine that this is a more expensive
> operation):
>
> > (define foo1 (foo 1 2))
> > (define foo2 (foo 7 12))
> > (foo-z foo1)
> 3
> > (foo-z foo2)
> 19
>

Yes, with the struct-plus-plus module.  As a bonus you can also typecheck
your arguments:

#lang racket

(require struct-plus-plus)
(struct++ foo
  ([x number?] [y number?] [(z #f)])
  (#:rule ("autogenerate z. overrides the provided value"
   #:transform z (x y) [(+ x y)]))
  #:transparent)

(define foo1 (foo++ #:x 1 #:y 2))
(define foo2 (foo++ #:x 7 #:y 12))
(foo-z foo1) ; 3
(foo-z foo2) ; 19

(define throws-exception (foo++ #:x 7 #:y "string")) ; contract violation


Note that the standard positional constructor is generated but does not
support the autocalculation feature or typechecking.  To get the advanced
features you need to use the keyword version.


>
> The closest I could find in the documentation was the #:auto property,
> but:
>
>1. it makes the field mutable, even though I'm not interested in
>mutating z
>2. the default value is fixed across all constructions, while I want z
>to depend on x and y
>
> Of course, I could make z an explicit field, write a custom constructor,
> and export that instead of the default constructor for foo. But that seems
> to be a Royal Pain, especially since (AFAIK) you can't provide the struct
> as a whole anymore. (And I need to write about 12 of these structs to boot.)
>
> --
> 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/9f9e1548-d01d-469f-b565-22601e02dd82n%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/CAE8gKofa5xPzBP%3DZpd0UjtBUdj7hHArPGtqKKxkUfz1g%3DSbaxQ%40mail.gmail.com.


Re: [racket-users] Freenode -> libera.chat

2021-05-20 Thread David Storrs
What happened with Freenode?

On Thu, May 20, 2021 at 8:12 AM Tony Garnock-Jones <
to...@leastfixedpoint.com> wrote:

> On 5/20/21 1:28 PM, Paulo Matos wrote:
> > Tony Garnock-Jones writes:
> >> With the recent damage to the Freenode IRC network, a new `#racket` has
> >> been founded on irc.libera.chat.
> >
> > Is this to become the canonical IRC chat room for Racket?
>
> ¯\_(ツ)_/¯
>
> I'd be in favour of moving off Freenode, myself.
>
> What would need updating? Presumably little more than the following:
>
>- https://racket-lang.org/irc-chat.html
>
> ? Is freenode mentioned anywhere else?
>
> Cheers,
>Tony
>
> --
> 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/4956afef-9ef6-cf9d-d2ce-61d83d3780ec%40leastfixedpoint.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/CAE8gKodDbgZ6jTi9sVN-950ZY_OPLdNvEqWCoZZp1p4gYoBJuQ%40mail.gmail.com.


Re: [racket-users] Sharing scope in setup/cleanup for dynamic-wind?

2021-05-19 Thread David Storrs
On Tue, May 18, 2021 at 4:09 PM Philip McGrath 
wrote:

> On Tue, May 18, 2021 at 3:52 PM Sam Tobin-Hochstadt 
> wrote:
>
>> I think the key question is what you want to happen if you would need
>> to re-run the "pre" thunk, because you re-enter the code via a
>> continuation.
>>
>> In many cases, you don't want to support that at all …
>>
>
> Then you can use `call-with-continuation-barrier`, right?
>
> (let* ([conn (connect-to-server)])
>   (dynamic-wind
>void
>(λ ()
>  (call-with-continuation-barrier
>   (λ ()
> (send-message conn "hi"
>(λ ()
>  (finalize-connection conn
>
> I think I don't understand cwcb well enough to get this, but the connect
call is not in the pre thunk so it's not guaranteed to happen...right?

-- 
> 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/0100017981191578-b5eaa465-de2a-4f1f-a4f1-d2976db88de0-00%40email.amazonses.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/CAE8gKodVmpqrNQMhEiX2QOi-CTQkO_s96%3Dgdoks4wt93%2Bmxy6g%40mail.gmail.com.


Re: [racket-users] Sharing scope in setup/cleanup for dynamic-wind?

2021-05-18 Thread David Storrs
Thank you.  Is there a way to do it without the mutation?  I was hoping to
use this for macro generation that simplifies combining with-handlers and
dynamic-wind with setup/teardown code.

(try [pre
  (define db (connect-to-db))
  (define conn (connect-to-server))]
 [(send-message conn (query-value db "invalid SQL"))]
 [catch ([exn:fail:contract? (lambda (e) (displayln "contract"))]
 [exn:fail:network?  (lambda (e) (displayln "network"))]
 [(and/c exn:fail? (compose1 (curry regexp-match #rx"query")
exn-message))
  (lambda (e) (displayln "database"))])]  ; this should run
 [finally
  (finalize-db-connection db)
  (finalize-server-connection conn)])

The goal is to guarantee that the connections are created/released every
time we go in and out of the code (usually via an exception) and also to
put the happy path first so that it's easier to see what the code should do
before getting into the weeds of error handling.

(I probably should have put these details in the original message but I was
trying to keep it simple so as not to make people burn brain cycles.)

On Tue, May 18, 2021 at 2:34 PM Sam Tobin-Hochstadt 
wrote:

> It's not quite as convenient, but here's a version of your program
> that should work:
>
> (let ([conn #f])
>   (dynamic-wind
> (lambda () (set! conn (connect-to-server))
> (lambda () (send-message conn "foo"))
> (lambda () (finalize-connection conn
>
> Sam
>
> On Tue, May 18, 2021 at 2:08 PM David Storrs 
> wrote:
> >
> > dynamic-wind is nice because it guarantees that the pre- and
> postconditions for a chunk of code will be run regardless of continuation
> jumps, exceptions, etc.  The only issue I have is that the three thunks do
> not share scope, making it difficult to do setup/teardown workflows.  I
> feel like I should be able to make this work with nested dynamic-wind or
> with-handlers but haven't been able to get there without losing the
> guarantee of running.  Is there a way?
> >
> > Example of what I'd like to do:
> >
> > (my-dynamic-wind
> >   (thunk (define conn (connect-to-server)))
> >   (thunk (send-message conn "foo"))
> >   (thunk (finalize-connection conn)))
> >
> > --
> > 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/CAE8gKodTcogsfeiYKu5iyFbL4H%2Ba3dzuL7rLTfYERD%2BauFD9xQ%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/CAE8gKofbcigfJDFgU8AXVqomQYqmgGT_OEXwAx7m8BQyyoCHqQ%40mail.gmail.com.


[racket-users] Sharing scope in setup/cleanup for dynamic-wind?

2021-05-18 Thread David Storrs
dynamic-wind is nice because it guarantees that the pre- and postconditions
for a chunk of code will be run regardless of continuation jumps,
exceptions, etc.  The only issue I have is that the three thunks do not
share scope, making it difficult to do setup/teardown workflows.  I feel
like I should be able to make this work with nested dynamic-wind or
with-handlers but haven't been able to get there without losing the
guarantee of running.  Is there a way?

Example of what I'd like to do:

(my-dynamic-wind
  (thunk (define conn (connect-to-server)))
  (thunk (send-message conn "foo"))
  (thunk (finalize-connection conn)))

-- 
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/CAE8gKodTcogsfeiYKu5iyFbL4H%2Ba3dzuL7rLTfYERD%2BauFD9xQ%40mail.gmail.com.


Re: [racket-users] Help in understanding 'letrec' example

2021-05-13 Thread David Storrs
Incidentally, a more concise way of doing this would be:

(define target (build-path "tarzan")) ; convert to path only once
(for/or ([item (in-directory "/tmp/test")]) ; or whatever directory you
want to start in
  (equal? target (file-name-from-path item)))

On Sat, May 8, 2021 at 3:50 AM Utkarsh Singh 
wrote:

> Hi,
>
> First of all I would like to thank Racket community for creating and
> maintaining top quality documentation at https://docs.racket-lang.org/
> and even providing a local copy for it.
>
> Currently I am having some difficulties in understanding this letrec
> example from Racket Guide docs
> (
> https://docs.racket-lang.org/guide/let.html#%28part._.Recursive_.Binding__letrec%29
> ):
>
> (letrec ([tarzan-near-top-of-tree?
>   (lambda (name path depth)
> (or (equal? name "tarzan")
> (and (directory-exists? path)
>  (tarzan-in-directory? path depth]
>  [tarzan-in-directory?
>   (lambda (dir depth)
> (cond
>   [(zero? depth) #f]
>   [else
>(ormap
> (λ (elem)
>   (tarzan-near-top-of-tree? (path-element->string elem)
> (build-path dir elem)
> (- depth 1)))
> (directory-list dir))]))])
>   (tarzan-near-top-of-tree? "tmp"
> (find-system-path 'temp-dir)
> 4))
>
> Problem:
> I having some problem on how recursion is working here and what is the
> problem we are solving here.  Are we finding a file with (name?
> "tarzan") or something else?
>
> --
> Utkarsh Singh
> http://utkarshsingh.xyz
>
> --
> 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/87h7jdslzh.fsf%40gmail.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/CAE8gKodbqAe6DB1rBKBckDWST6f75OV4_35-dcceR7neNfHuaA%40mail.gmail.com.


Re: [racket-users] Is there a good Racket DSL alternative to Image Magick?

2021-05-13 Thread David Storrs
On Wed, May 12, 2021 at 9:21 PM Ben Greenman 
wrote:

> On 5/12/21, Robert Haisfield  wrote:
> > Daniel, that's awesome. How would I filter down this list according to
> the
> > regex?
> >
> > (define list-of-files (map path->string (directory-list starting-path)))
>
> You can wrap it in a filter:
>
>   (define list-of-files (filter (lambda (str) (regexp-match? "\\.png$"
> str)) (map path->string (directory-list starting-path
>

Alternatively, if you would like to keep them as paths instead of strings
then you can do this:

(filter (compose1 (curry regexp-match? "\\.png$") path->string)
(directory-list "."))


Also, if you're going to be doing a lot of work with regexen, take a look
at the at-exp reader so that you don't have to do so much backwhacking
(obviously it's not important in this case where there's only one character
to escape, but it gets helpful as you do more):

#lang at-exp racket
(filter (compose1 (curry regexp-match? @~a{\.png}) path->string)
(directory-list "."))

-- 
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/CAE8gKoe1Nrx%3DU9draN1q%2BokxefrPvH%3D0tq3B8rL5hwAKpXOPRQ%40mail.gmail.com.


Re: [racket-users] Injecting local contracts for prefab constructors

2021-05-12 Thread David Storrs
If you're willing to accept a low tech solution, might I suggest this:

$ perl -i.bak -lpe 's/\(foo/\(make-foo/g' *.rkt


Also, I'll self-plug and point you towards this:

#lang racket
(require struct-plus-plus )

(struct++ foo ([a real?]) (#:omit-reflection) #:prefab)

(define checked (foo++ #:a 7)) ; contract is checked

(define not-checked (foo 7)) ; contract is not checked

(writeln checked)
(writeln not-checked)

This defines the contracts using define/contract.  It's not clear to me if
that meets your needs, but hopefully it does.

On Mon, May 10, 2021 at 10:03 AM Sage Gerard  wrote:

> I hope so! That's what I understood option B to mean.
>
> I could adjust the define-message macro according to the info in Ryan and
> Phillip's attachments, but I'm not well-educated on trapping struct
> operations. Phillip: Your example and email gives me the impression that
> when you add a chaperone, you can proxy all struct operations, including
> the gap left by the chaperone for the constructor. Is that true?
>
> The macro I'd want has to preserve *all* characteristics of *all*
> generated struct bindings, which makes things tricky since the options for
> `struct` normally operate on a strict subset. e.g.
> #:[extra-]constructor-name seems to operate on the constructor alone, and
> the #:extra- variant does not preserve the match-expander/super-id
> characteristics. #:constructor-name is closer, but the original constructor
> id is no longer directly callable by the declaring module.
> On 5/10/21 7:05 AM, Hendrik Boom wrote:
>
> On Sun, May 09, 2021 at 10:23:34PM +, Sage Gerard wrote:
>
> I have a project with 57 prefab structure types. I need to construct 
> instances using a local contract (module level contracts do not fit my needs 
> here). Since I cannot define guards, the solution is easy enough.
>
> (struct foo (num) #:prefab)
> (define/contract make-foo (-> real? foo?) foo)
>
> Problem: I already have a few hundred constructor calls without
> contracts. I could either A) rewrite them all to use contracted
> constructors, or B) attach local contracts in a sweet spot so that I
> don't have to rewrite anything else.
>
> Is there any chance you could do the "rewriting" in a macro so you
> wouldn't actually have to change the few hundred constructor calls
> when you use option A)?
>
> -- hendrik
>
>
> I prefer option B, but it doesn't look like I can attach a local contract to 
> a constructor with `struct` alone, or even with an impersonator. When I hack 
> around to rebind or hide the constructor's identifier, I break compatibility 
> with `match` and `defstruct*`.
>
> If you were in my position, what would you do?
>
> --
>
> ~slg
>
> --
> 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/0a16cfbe-4789-a939-796e-5f6f9da21626%40sagegerard.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/20210510110509.cpg6jnil6th7xbsi%40topoi.pooq.com.
>
> --
> ~slg
>
> --
> 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/94e81fc9-e8a1-e677-bf0e-b49e597313b9%40sagegerard.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/CAE8gKofQDbSrOS1n-i7B-T0h78x%2Bz0NRdUkZx6-1T9FyxBspBQ%40mail.gmail.com.


Re: [racket-users] Running user-supplied code in a place

2021-04-07 Thread David Storrs
Thanks, George.  This helped a lot.

On Wed, Apr 7, 2021 at 9:03 PM George Neuner  wrote:
>
>
> On 4/7/2021 5:34 PM, David Storrs wrote:
> > I'm trying to expand a task manager to optionally use places and I'm
> > having some trouble understanding the issue.
> >
> > ; test.rkt
> > #lang racket
> > (provide start)
> > (define (start thnk)
> >(sync (place ch  (place-channel-put ch  (thnk)
> >
> > ; x.rkt
> > #lang racket
> > (require "test.rkt")
> > (start (thunk 'ok))
> >
> > Result:  ; identifier used out of context: #<[...]/test.rkt:5:19 thnk>
> >
> > I know that the place is creating a submodule which closes over the
> > place id ('ch') and the top level declarations, meaning only 'start'.
> > The argument to start is not at top level so it's invisible in the
> > submodule, meaning that the place code can't use it.
> >
> > I feel like parallelizing a function at runtime should be a primary
> > use case for places but I'm not sure how to progress.
> > Things I tried:
> >
> > *) Passing the thunk in via place-channel-put, but functions are
> > place-message-allowed? #f.
> > *) Creating a top-level parameter into which I put the thnk at
> > runtime.  Same problem.
> >
> > Am I fundamentally misunderstanding something?
>
> It helps if you think about places as being separate processes (even
> when they aren't).
>
> Dynamic places (threads in same process) can see code that is in scope
> at the point where the place is created.  This includes top level
> functions in the module that created the place.  In your example 'thunk'
> was created in a different module so the place didn't know about it.
>
> There are ways to communicate new code to a place - very useful for
> distributed (separate process) places, but also works with dynamic
> places if you can't arrange that everything they need is visible to them
> at creation.
>
> 1.  send the name of a (local to the place) file to be dynamically required
> 2.  send the file itself and have the place save it locally before
> requiring it
> 3.  send serialized functions and have the place instantiate them
>
> Obviously, the place must have startup code available to it which
> understands how to load / execute new code.
>
>
> Take a look at  'serialize', 'serial-lambda', and 's-exp->fasl'.   Also
> see Tony Garnok's racket-reloadable project:
> https://github.com/tonyg/racket-reloadable
>
>
> Hope this helps,
> George
>

-- 
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/CAE8gKod%3D78B5Ls6ybZESsbYs5RVw4yf7xRniaoiyNpG_nG6jmg%40mail.gmail.com.


Re: [racket-users] Werid contract violation blame erros

2021-04-07 Thread David Storrs
I've always liked define/contract because it guarantees the safety of
the function from erroneous calls by other functions in the module,
which helps with debugging and testing.  It sounds like you think
that's a bad move?

On Wed, Apr 7, 2021 at 4:35 PM Robby Findler  wrote:
>
> The short answer: you probably should use (provide (contract-out)) 
> instead of define/contract.
>
> The slightly longer answer: when you write a contract, you are not just 
> describing what the legal inputs and outputs are, you are also establishing a 
> *boundary* between two regions of code. In the case of define/contract, you 
> are establishing a boundary between the function (here: f) and the module 
> that it contains (here the file "a.rkt"). In the case of (provide 
> (contract-out  ...)) the boundary is between a.rkt and b.rkt.
>
> The slightly uncomfortable answer: it is my (not completely solid yet) 
> opinion that the boundary that is drawn for define/contract is perhaps not 
> the right / best one. In a theoretical/mathematical sense it is a completely 
> fine and completely defensible one. But it trips people up sometimes. (There 
> are examples others have posted in the past that are perhaps even stranger 
> than yours but boil down to the same specific design choice for 
> define/contract.)
>
> Robby
>
>
>
> On Wed, Apr 7, 2021 at 2:10 PM epi via Racket Users 
>  wrote:
>>
>> Hello Racket users,
>>
>> I am trying to understand a contract violation message that I am getting.
>> Here is the file a.rkt:
>>
>> #lang racket
>> (provide f)
>> (define/contract (f a)
>>   (-> boolean? any/c)
>>   '())
>>
>> and this is b.rkt:
>>
>> #lang racket
>> (require "a.rkt")
>> (f 3)
>>
>>
>> I would expect that the caller is blamed for the contract violation, but the 
>> error message that I get is as follows:
>>
>>
>> f: contract violation
>>   expected: boolean?
>>   given: 3
>>   in: the 1st argument of
>>   (-> boolean? any/c)
>>   contract from: (function f)
>>   blaming: /home/epi/snippets/a.rkt
>>(assuming the contract is correct)
>>   at: /home/epi/snippets/a.rkt:3.18
>>   context...:
>>/usr/share/racket/collects/racket/contract/private/blame.rkt:347:0: 
>> raise-blame-error
>>
>> /usr/share/racket/collects/racket/contract/private/arrow-higher-order.rkt:379:33
>>body of "/home/dan/snippets/blameme.rkt"
>>
>> So, I am a bit surprised that the error message blames the file a.rkt.
>> What am I missing 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.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/racket-users/149cfc632cd666ff1a92177dce90296b%40disroot.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/CAL3TdONLMx%3Dy_cgfDsY_k9L9yaX_touO52phiK9scziW_jGrOA%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/CAE8gKofSq%3DvzFV3jt3fkMbzMqV%3Dt9%2BHtj1y02Nsku_ZXF6%2BB5A%40mail.gmail.com.


[racket-users] Running user-supplied code in a place

2021-04-07 Thread David Storrs
I'm trying to expand a task manager to optionally use places and I'm
having some trouble understanding the issue.

; test.rkt
#lang racket
(provide start)
(define (start thnk)
  (sync (place ch  (place-channel-put ch  (thnk)

; x.rkt
#lang racket
(require "test.rkt")
(start (thunk 'ok))

Result:  ; identifier used out of context: #<[...]/test.rkt:5:19 thnk>

I know that the place is creating a submodule which closes over the
place id ('ch') and the top level declarations, meaning only 'start'.
The argument to start is not at top level so it's invisible in the
submodule, meaning that the place code can't use it.

I feel like parallelizing a function at runtime should be a primary
use case for places but I'm not sure how to progress.  Things I tried:

*) Passing the thunk in via place-channel-put, but functions are
place-message-allowed? #f.
*) Creating a top-level parameter into which I put the thnk at
runtime.  Same problem.

Am I fundamentally misunderstanding something?

-- 
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/CAE8gKoc2v81%2BAHTn0YniCS8SEqYT0Ngz5qztTNh%3D0LUZyWeoGQ%40mail.gmail.com.


Re: [racket-users] How to make a sandboxed evaluator in Scribble

2021-04-01 Thread David Storrs
On Thu, Apr 1, 2021 at 3:58 PM Sam Tobin-Hochstadt  wrote:
>
> You might use `(list 'value-evt)` if that's the require you want.
>
> Sam

...
Blarg.

Yes, thank you.  Should have realized.

>
> On Thu, Apr 1, 2021 at 3:41 PM David Storrs  wrote:
> >
> > I cargo-culted this chunk of code and, predictably, it is now failing
> > for reasons I don't understand.  This is in the value-evt scribble
> > file; it works fine when I build the file manually but it's failing in
> > the package server build:
> >
> > @(define eval
> >(call-with-trusted-sandbox-configuration
> > (lambda ()
> >   (parameterize ([sandbox-output 'string]
> >  [sandbox-error-output 'string]
> >  [sandbox-memory-limit 50])
> > [make-evaluator #:requires (list "main.rkt") 'racket]
> >
> > Clearly the issue is with 'main.rkt' as opposed to '../main.rkt'.  I
> > had that originally and it worked when I did 'scribble
> > value-evt.scrbl' while in the scribblings directory but it failed or
> > misgenerated the files when I was in a different directory or I used
> > raco setup.
> >
> > Weirdly, this is being reported as a failing test, which surprised me.
> > Why is that?
> >
> > What should I do instead?
> >
> > --
> > 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/CAE8gKofQXNm%2Bsfkk-07NYZw0drQmw92oqJBZkyq5fQrGBWA9TQ%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/CAE8gKoehaCTbR9iurUBRrGbRE%3DcsRsVpnApDJy8zzZ87dDdQbw%40mail.gmail.com.


[racket-users] How to make a sandboxed evaluator in Scribble

2021-04-01 Thread David Storrs
I cargo-culted this chunk of code and, predictably, it is now failing
for reasons I don't understand.  This is in the value-evt scribble
file; it works fine when I build the file manually but it's failing in
the package server build:

@(define eval
   (call-with-trusted-sandbox-configuration
(lambda ()
  (parameterize ([sandbox-output 'string]
 [sandbox-error-output 'string]
 [sandbox-memory-limit 50])
[make-evaluator #:requires (list "main.rkt") 'racket]

Clearly the issue is with 'main.rkt' as opposed to '../main.rkt'.  I
had that originally and it worked when I did 'scribble
value-evt.scrbl' while in the scribblings directory but it failed or
misgenerated the files when I was in a different directory or I used
raco setup.

Weirdly, this is being reported as a failing test, which surprised me.
Why is that?

What should I do instead?

-- 
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/CAE8gKofQXNm%2Bsfkk-07NYZw0drQmw92oqJBZkyq5fQrGBWA9TQ%40mail.gmail.com.


Re: [racket-users] New package announce: value-evt

2021-04-01 Thread David Storrs
Sorawee:  Thanks, glad to hear that it worked for you.

Sage:  Brilliant, that did it.  In the scribblings/ directory it
created a compiled/ directory with the data instead of generating the
.html file directly, but it is in the local copy of the Reference.
Thanks very much!   I've removed the '(), pushed the new version, and
asked the package server to rescan.

On Thu, Apr 1, 2021 at 12:37 PM Sage Gerard  wrote:
>
> I compared the info.rkt files between your thread-with-id library and
> value-evt. One thing that stands out is the extra empty list in
> value-evt. I'm wondering if that hid defaults that would otherwise be
> provided.
>
> https://github.com/dstorrs/value-evt/blob/master/info.rkt
> https://github.com/dstorrs/thread-with-id/blob/master/info.rkt
>
> If that's not it, I'd have to take time after work to look more closely.
>
> On 4/1/21 12:31 PM, David Storrs wrote:
> > On Thu, Apr 1, 2021 at 12:18 PM Sage Gerard  wrote:
> >> Neat! Thanks for this. Did you make sure to list your scribble file in
> >> `scribblings` under info.rkt?
> >>
> > I did, yes.
> >
> > Although, now that you mention it, when I do raco setup value-evt it
> > does all the things, says "Building documentation" but the .html file
> > did not appear in the directory and it's not linked into my local doc
> > set.  I hadn't noticed because I had previously created the file
> > directly using 'scribble value-evt.scrbl'  What might I have done
> > wrong?
> >
> >> On 4/1/21 12:12 PM, David Storrs wrote:
> >>> Wraps an arbitrary value into a synchronizable event. The
> >>> synchronization result of the event is the original value, with two
> >>> exceptions: procedures sync to their return value and lists sync
> >>> recursively. Both of these values can be disabled via keywords.
> >>>
> >>> The package server is telling me that it needs documentation.  That
> >>> confuses me since it has a .scrbl file and the .html was already
> >>> present in the repository.  ISTR that the docs are only built once
> >>> every 24 hours, so presumably they will pop up at some point?
> >>>
> >>> Examples:
> >>>
> >>> ; value-evts are both evt? and value-evt?. They sync to their argument
> >>>> (define e (value-evt 9))
> >>>> e
> >>> #
> >>>> (evt? e)
> >>> #t
> >>>> (value-evt? e)
> >>> #t
> >>>> (sync e)
> >>> 9
> >>> ;
> >>> ; By default, syncing on a procedure syncs to the return value
> >>>> (define proc (lambda () (+ 2 2)))
> >>>> (sync (value-evt proc))
> >>> 4
> >>> ;
> >>> ; You can instead get the procedure itself back
> >>>> (sync (value-evt proc #:eval-proc? #f))
> >>> #
> >>> ;
> >>> ; It's not a problem to specify #:eval-proc? on something that isn't a 
> >>> procedure
> >>>> (sync (value-evt "eval-proc? keyword is ignored for non-proc" 
> >>>> #:eval-proc? #f))
> >>> "eval-proc? keyword is ignored for non-proc"
> >>> ;
> >>> ; eventify always returns an evt
> >>> ; Things that are evts are unchanged
> >>>> (define ch (make-channel))
> >>>> (evt? ch)
> >>> #t
> >>>> (eq? ch (eventify ch))
> >>> #t
> >>> ;
> >>> ; Things that are not evts become value-evts
> >>>> (evt? 'bob)
> >>> #f
> >>>> (evt? (eventify 'bob))
> >>> #t
> >>> ;
> >>> ; by default, value-evts containing a list sync recursively
> >>>> (let ([result-ch (make-channel)]
> >>>   [arg-ch1   (make-channel)]
> >>>   [arg-ch2   (make-channel)])
> >>>   (void (thread (λ () (channel-put result-ch (sync (value-evt (list
> >>> arg-ch1 arg-ch2)))
> >>>   (channel-put arg-ch1 'arg1-ch-ok)
> >>>   (channel-put arg-ch2 'arg2-ch-ok)
> >>>   (sync result-ch))
> >>> '(arg1-ch-ok arg2-ch-ok)
> >>> ;
> >>> ; You can ask for it to return the original list
> >>>> (let ([arg-ch1   (make-channel)]
> >>>   [arg-ch2   (make-channel)])
> >>> (sync (value-evt (list arg-ch1 arg-ch2) #:recurse-lists? #f)))
> >>> '(# #)
> >>> ;
> >>> ; all-evt is the same as value-evt but takes a rest argument
> >>> ; so you don't 

Re: [racket-users] New package announce: value-evt

2021-04-01 Thread David Storrs
On Thu, Apr 1, 2021 at 12:18 PM Sage Gerard  wrote:
>
> Neat! Thanks for this. Did you make sure to list your scribble file in
> `scribblings` under info.rkt?
>

I did, yes.

Although, now that you mention it, when I do raco setup value-evt it
does all the things, says "Building documentation" but the .html file
did not appear in the directory and it's not linked into my local doc
set.  I hadn't noticed because I had previously created the file
directly using 'scribble value-evt.scrbl'  What might I have done
wrong?

> On 4/1/21 12:12 PM, David Storrs wrote:
> > Wraps an arbitrary value into a synchronizable event. The
> > synchronization result of the event is the original value, with two
> > exceptions: procedures sync to their return value and lists sync
> > recursively. Both of these values can be disabled via keywords.
> >
> > The package server is telling me that it needs documentation.  That
> > confuses me since it has a .scrbl file and the .html was already
> > present in the repository.  ISTR that the docs are only built once
> > every 24 hours, so presumably they will pop up at some point?
> >
> > Examples:
> >
> > ; value-evts are both evt? and value-evt?. They sync to their argument
> >> (define e (value-evt 9))
> >> e
> > #
> >> (evt? e)
> > #t
> >> (value-evt? e)
> > #t
> >> (sync e)
> > 9
> > ;
> > ; By default, syncing on a procedure syncs to the return value
> >> (define proc (lambda () (+ 2 2)))
> >> (sync (value-evt proc))
> > 4
> > ;
> > ; You can instead get the procedure itself back
> >> (sync (value-evt proc #:eval-proc? #f))
> > #
> > ;
> > ; It's not a problem to specify #:eval-proc? on something that isn't a 
> > procedure
> >> (sync (value-evt "eval-proc? keyword is ignored for non-proc" #:eval-proc? 
> >> #f))
> > "eval-proc? keyword is ignored for non-proc"
> > ;
> > ; eventify always returns an evt
> > ; Things that are evts are unchanged
> >> (define ch (make-channel))
> >> (evt? ch)
> > #t
> >> (eq? ch (eventify ch))
> > #t
> > ;
> > ; Things that are not evts become value-evts
> >> (evt? 'bob)
> > #f
> >> (evt? (eventify 'bob))
> > #t
> > ;
> > ; by default, value-evts containing a list sync recursively
> >> (let ([result-ch (make-channel)]
> >  [arg-ch1   (make-channel)]
> >  [arg-ch2   (make-channel)])
> >  (void (thread (λ () (channel-put result-ch (sync (value-evt (list
> > arg-ch1 arg-ch2)))
> >  (channel-put arg-ch1 'arg1-ch-ok)
> >  (channel-put arg-ch2 'arg2-ch-ok)
> >  (sync result-ch))
> > '(arg1-ch-ok arg2-ch-ok)
> > ;
> > ; You can ask for it to return the original list
> >> (let ([arg-ch1   (make-channel)]
> >  [arg-ch2   (make-channel)])
> >(sync (value-evt (list arg-ch1 arg-ch2) #:recurse-lists? #f)))
> > '(# #)
> > ;
> > ; all-evt is the same as value-evt but takes a rest argument
> > ; so you don't have to supply your own list
> >> (let ([result-ch (make-channel)]
> >  [arg-ch1   (make-channel)]
> >  [arg-ch2   (make-channel)])
> >  (define e (all-evt  arg-ch1 arg-ch2))
> >  (printf "all-evt returns: ~v" e)
> >  (void (thread (λ () (channel-put result-ch (sync e)
> >  (channel-put arg-ch1 'arg1-ch-ok)
> >  (channel-put arg-ch2 'arg2-ch-ok)
> >  (sync result-ch))
> > all-evt returns: #
> > '(arg1-ch-ok arg2-ch-ok)
> >
> > --
> > 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/CAE8gKocr0FbpTKwgNcseNjjA_-64f4exQDkgfPPxxvFpR16pww%40mail.gmail.com.
>
> --
> ~slg
>
>
> --
> 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/99793234-257c-d8e5-7454-a1d911d2ab66%40sagegerard.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/CAE8gKodjGk3Ktp3MshXSfU%3DN2G7JkMhdSBF_VFiPRsBz2%3D6tuA%40mail.gmail.com.


[racket-users] New package announce: value-evt

2021-04-01 Thread David Storrs
Wraps an arbitrary value into a synchronizable event. The
synchronization result of the event is the original value, with two
exceptions: procedures sync to their return value and lists sync
recursively. Both of these values can be disabled via keywords.

The package server is telling me that it needs documentation.  That
confuses me since it has a .scrbl file and the .html was already
present in the repository.  ISTR that the docs are only built once
every 24 hours, so presumably they will pop up at some point?

Examples:

; value-evts are both evt? and value-evt?. They sync to their argument
> (define e (value-evt 9))
> e
#
> (evt? e)
#t
> (value-evt? e)
#t
> (sync e)
9
;
; By default, syncing on a procedure syncs to the return value
> (define proc (lambda () (+ 2 2)))
> (sync (value-evt proc))
4
;
; You can instead get the procedure itself back
> (sync (value-evt proc #:eval-proc? #f))
#
;
; It's not a problem to specify #:eval-proc? on something that isn't a procedure
> (sync (value-evt "eval-proc? keyword is ignored for non-proc" #:eval-proc? 
> #f))
"eval-proc? keyword is ignored for non-proc"
;
; eventify always returns an evt
; Things that are evts are unchanged
> (define ch (make-channel))
> (evt? ch)
#t
> (eq? ch (eventify ch))
#t
;
; Things that are not evts become value-evts
> (evt? 'bob)
#f
> (evt? (eventify 'bob))
#t
;
; by default, value-evts containing a list sync recursively
> (let ([result-ch (make-channel)]
[arg-ch1   (make-channel)]
[arg-ch2   (make-channel)])
(void (thread (λ () (channel-put result-ch (sync (value-evt (list
arg-ch1 arg-ch2)))
(channel-put arg-ch1 'arg1-ch-ok)
(channel-put arg-ch2 'arg2-ch-ok)
(sync result-ch))
'(arg1-ch-ok arg2-ch-ok)
;
; You can ask for it to return the original list
> (let ([arg-ch1   (make-channel)]
[arg-ch2   (make-channel)])
  (sync (value-evt (list arg-ch1 arg-ch2) #:recurse-lists? #f)))
'(# #)
;
; all-evt is the same as value-evt but takes a rest argument
; so you don't have to supply your own list
> (let ([result-ch (make-channel)]
[arg-ch1   (make-channel)]
[arg-ch2   (make-channel)])
(define e (all-evt  arg-ch1 arg-ch2))
(printf "all-evt returns: ~v" e)
(void (thread (λ () (channel-put result-ch (sync e)
(channel-put arg-ch1 'arg1-ch-ok)
(channel-put arg-ch2 'arg2-ch-ok)
(sync result-ch))
all-evt returns: #
'(arg1-ch-ok arg2-ch-ok)

-- 
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/CAE8gKocr0FbpTKwgNcseNjjA_-64f4exQDkgfPPxxvFpR16pww%40mail.gmail.com.


[racket-users] Package server certificate expired

2021-04-01 Thread David Storrs
Not sure where the right place is to report this, but  the certificate for
pkgd.racket-lang.org expired on 3/31/2021.

-- 
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/CAE8gKocWHJYQQdYk0BEFx_EPJc%2Bc0yoAZe1NqJ6HNZRSHa2Y5A%40mail.gmail.com.


Re: [racket-users] Re: Racket on Corporate Desktop Windows

2021-03-30 Thread David Storrs
Slightly offtopic, but I wanted to point out that when GMail sees a
conversation happening it collapses all the emails into one line and
displays the first names of the first two posters side-by-side with the
subject.  I am tickled to have a thread from Bruce O'Neel and Wayne Harris
in my email.

On Tue, Mar 30, 2021 at 6:51 AM 'Wayne Harris' via Racket Users <
racket-users@googlegroups.com> wrote:

> "Bruce O'Neel" 
> writes:
>
> [...]
>
> > But no GUI of course.
> >
> > Well I had been building on MacOS for years following the instructions
> > to build a Minimal Racket and then run
> >
> > raco pkg install -i main-distribution
> >
> > and it finally clicked that the instructions were almost identical for
> > Windows.
> >
> > raco pkg update --auto racket-lib raco pkg install -i
> > main-distribution
> >
> > just like the instructions said.  In my mind I thought "I don't have a
> > build toolchain on Windows, so that won't work."  And I was wrong.  It
> > works just fine on my locked down desktop and now I have a GUI Dr
> > Racket as well.
>
> Cool!  Thanks for sharing!
>
> --
> 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/86h7kw7b91.fsf%40protonmail.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/CAE8gKoexPXxU6eUKj5TsU1Um5RKd640Uj8J8F-vEYuOnQGznPQ%40mail.gmail.com.


Re: [racket-users] Best way to say 'block until true'?

2021-03-19 Thread David Storrs
Ah. Thanks.

On Fri, Mar 19, 2021 at 1:33 PM Jay McCarthy  wrote:

> It is not a built-in thing. I am talking about the use-pattern of a
> condition variable:
> https://en.wikipedia.org/wiki/Monitor_(synchronization)#Condition_variables
>
> --
> Jay McCarthy
> Associate Professor @ CS @ UMass Lowell
> http://jeapostrophe.github.io
> Vincit qui se vincit.
>
> On Fri, Mar 19, 2021 at 1:02 PM David Storrs 
> wrote:
> >
> >
> >
> > On Fri, Mar 19, 2021 at 12:02 PM Jay McCarthy 
> wrote:
> >>
> >> The best thing is to use a semaphore instead of a mutable reference.
> >> If you can't do that, then I think that you should combine the mutable
> >> reference with a signaling semaphore. If you can't do that, then I
> >> can't think of anything but a poll.
> >
> >
> > Is this the kind of thing you meant by 'signalling semaphore'?
> >
> > #lang racket
> >
> > (define x #f)
> > (define sema (make-semaphore 0))
> >
> > (define (wait-on-x) (sync (semaphore-peek-evt sema)) always-evt)
> > (define (set-x! val)
> >   (void (thread ; don't print the thread object when running in the repl
> >  (thunk
> >   (sleep 3)
> >   (set! x val)
> >   (semaphore-post sema)
> >
> > (define (check-x)
> >   (match (sync/timeout 10 (wait-on-x))
> > [#f (displayln "timeout")]
> > [_ (displayln "success")]))
> >
> > (set-x! 7)
> > (check-x)  ; pauses for 3 seconds, then outputs "success"
> > (check-x)  ; outputs "success" immediately
> > (check-x)  ; ibid
> >>
> >>
> >> --
> >> Jay McCarthy
> >> Associate Professor @ CS @ UMass Lowell
> >> http://jeapostrophe.github.io
> >> Vincit qui se vincit.
> >>
> >> On Fri, Mar 19, 2021 at 11:59 AM David Storrs 
> wrote:
> >> >
> >> > Suppose I have a function that tests for some condition, e.g.
> >> >
> >> > (define current-user (make-parameter #f))
> >> > (define (current-user-set?) (not (false? (current-user)))
> >> >
> >> > What is the best way to say "wait until 'current-user-set?' returns
> true"?  I've been through the Events chapter in the Reference and nothing
> seems like a great fit.  I could do polling via sleep or alarm-evt but that
> seems inefficient.  Is there a better way?
> >> >
> >> > --
> >> > 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/CAE8gKocbPgjcFAF_o2g6mhZBEH8PpeGyJ4CwznKc3DZkMjY%3DGw%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/CAE8gKofsHVJfBZCX12Sm%3DeNSeEj4AmehPYhsS2wJf8G3q%3DRXXA%40mail.gmail.com.


Re: [racket-users] Best way to say 'block until true'?

2021-03-19 Thread David Storrs
On Fri, Mar 19, 2021 at 12:02 PM Jay McCarthy 
wrote:

> The best thing is to use a semaphore instead of a mutable reference.
> If you can't do that, then I think that you should combine the mutable
> reference with a signaling semaphore. If you can't do that, then I
> can't think of anything but a poll.
>

Is this the kind of thing you meant by 'signalling semaphore'?

#lang racket

(define x #f)
(define sema (make-semaphore 0))

(define (wait-on-x) (sync (semaphore-peek-evt sema)) always-evt)
(define (set-x! val)
  (void (thread ; don't print the thread object when running in the repl

 (thunk
  (sleep 3)
  (set! x val)
  (semaphore-post sema)

(define (check-x)
  (match (sync/timeout 10 (wait-on-x))
[#f (displayln "timeout")]
[_ (displayln "success")]))

(set-x! 7)
(check-x)  ; pauses for 3 seconds, then outputs "success"
(check-x)  ; outputs "success" immediately
(check-x)  ; ibid

>
> --
> Jay McCarthy
> Associate Professor @ CS @ UMass Lowell
> http://jeapostrophe.github.io
> Vincit qui se vincit.
>
> On Fri, Mar 19, 2021 at 11:59 AM David Storrs 
> wrote:
> >
> > Suppose I have a function that tests for some condition, e.g.
> >
> > (define current-user (make-parameter #f))
> > (define (current-user-set?) (not (false? (current-user)))
> >
> > What is the best way to say "wait until 'current-user-set?' returns
> true"?  I've been through the Events chapter in the Reference and nothing
> seems like a great fit.  I could do polling via sleep or alarm-evt but that
> seems inefficient.  Is there a better way?
> >
> > --
> > 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/CAE8gKocbPgjcFAF_o2g6mhZBEH8PpeGyJ4CwznKc3DZkMjY%3DGw%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/CAE8gKofBk8YjrDMXHykwJBspE5%2BOGDKhC16O%3DP96aXLe0pP90w%40mail.gmail.com.


Re: [racket-users] Best way to say 'block until true'?

2021-03-19 Thread David Storrs
Cool.  Thank you both.

On Fri, Mar 19, 2021 at 12:15 PM Sam Tobin-Hochstadt 
wrote:

> Another possibility is to send a message on a channel when the user is
> set, and then just wait with `sync` for a message to appear on the
> channel.
>
> Sam
>
> On Fri, Mar 19, 2021 at 12:02 PM Jay McCarthy 
> wrote:
> >
> > The best thing is to use a semaphore instead of a mutable reference.
> > If you can't do that, then I think that you should combine the mutable
> > reference with a signaling semaphore. If you can't do that, then I
> > can't think of anything but a poll.
> >
> > --
> > Jay McCarthy
> > Associate Professor @ CS @ UMass Lowell
> > http://jeapostrophe.github.io
> > Vincit qui se vincit.
> >
> > On Fri, Mar 19, 2021 at 11:59 AM David Storrs 
> wrote:
> > >
> > > Suppose I have a function that tests for some condition, e.g.
> > >
> > > (define current-user (make-parameter #f))
> > > (define (current-user-set?) (not (false? (current-user)))
> > >
> > > What is the best way to say "wait until 'current-user-set?' returns
> true"?  I've been through the Events chapter in the Reference and nothing
> seems like a great fit.  I could do polling via sleep or alarm-evt but that
> seems inefficient.  Is there a better way?
> > >
> > > --
> > > 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/CAE8gKocbPgjcFAF_o2g6mhZBEH8PpeGyJ4CwznKc3DZkMjY%3DGw%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/CAJYbDanE4zqgFRAFSYs4kdLzjKf9xg3xi0JMNU7VmFREstNBgQ%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/CAE8gKoeCDA653EC78oM-ZLZ3Ok%3Ds0%3DTczO96ggVh%2B6EBA-%2BVjQ%40mail.gmail.com.


[racket-users] Best way to say 'block until true'?

2021-03-19 Thread David Storrs
Suppose I have a function that tests for some condition, e.g.

(define current-user (make-parameter #f))
(define (current-user-set?) (not (false? (current-user)))

What is the best way to say "wait until 'current-user-set?' returns true"?
I've been through the Events chapter in the Reference and nothing seems
like a great fit.  I could do polling via sleep or alarm-evt but that seems
inefficient.  Is there a better way?

-- 
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/CAE8gKocbPgjcFAF_o2g6mhZBEH8PpeGyJ4CwznKc3DZkMjY%3DGw%40mail.gmail.com.


Re: [racket-users] Word Count program/benchmark performance

2021-03-18 Thread David Storrs
Hi Pawel,

I'll take a look at the code later, but did that 21 seconds include startup
time for the interpreter?

On Thu, Mar 18, 2021, 9:24 AM Pawel Mosakowski  wrote:

> Hello,
>
> I am a Racket beginner and I have come across this article:
>
> 
> https://benhoyt.com/writings/count-words/
>
> This is my attempt at solving the challenge:
>
> 
> https://pastebin.com/kL16w5Hc
>
> However when I have benchmarked it, it takes ~21 seconds to run compared
> to the Python and Ruby versions which take around 3-4 seconds.
>
> I understand that both Ruby and Python probably have the string operations
> and hash tables implemented in optimized C but is there anything I can do
> to improve performance of my program?
>
> Many thanks for all help and suggestions.
>
> --
> 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/118c1340-66d1-421d-92a4-6b66c56cb88fn%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/CAE8gKoego85qz3O%2B4-PMq-YpX2ygmXEW3a62asYO5e_hxANZ0A%40mail.gmail.com.


Re: [racket-users] fluent: unix style pipes and lambda shorthand to make your code more readable

2021-03-09 Thread David Storrs
This is very cool.  You might take a look at the `threading` module for
additional ideas: https://docs.racket-lang.org/threading/index.html

On Tue, Mar 9, 2021 at 10:20 AM Roger Keays  wrote:

> Hi all,
>
> I recently publish a new package called *fluent* which adds some syntax
> enhancements to Racket. Links and README below. Let me know what you
> think...
>
> Roger
>
> https://pkgs.racket-lang.org/package/fluent
> https://github.com/rogerkeays/racket-fluent/
>
> # fluent
>
> UNIX style pipes and a lambda shorthand syntax to make your Racket code
> more readable.
>
> ## ? Unpopular So LISP Is Why
>
> Let's be honest. LISP missed a huge opportunity to change the world by
> telling developers they have to think backwards. Meanwhile, UNIX became
> successful largely because it allows you to compose programs sequentially
> using pipes. Compare the difference (the LISP example is actually racket):
>
> UNIX: cat data.txt | grep "active" | cut -f 4 | uniq | sort
> LISP: (sort (remove-duplicates (map (λ (line) (list-ref (string-split
> line) 4)) ((filter (λ (line) (string-contains? line "active")) (file->lines
> "data.txt"))
>
> Using *fluent*, the same racket code can be written according to the UNIX
> philosophy:
>
> ("data.txt" > file->lines >> filter (line : line > string-contains?
> "active") >> map (line : line > string-split > list-ref 4) >
> remove-duplicates > sort)
>
> You can use unicode → instead of > if you prefer. It is more distinctive
> and a bit easier on the eyes:
>
> ("data.txt" → file->lines →→ filter (line : line → string-contains?
> "active") →→ map (line : line → string-split → list-ref 4) →
> remove-duplicates → sort)
>
> ## Function Composition
>
> Using the function composition operator (> or →), *fluent* inserts the
> left hand side as the first parameter to the procedure on the right hand
> side. Use >> (or →→) to add the left hand side as the last parameter to the
> procedure.
>
> (data > procedure params) becomes(procedure data params)
> (data >> procedure params)becomes(procedure params data)
>
> This operation can be chained or nested as demonstrated in the examples.
>
> ## Lambda Shorthand
>
> The : operator allows you to easily write a lambda function with one
> expression. Parameters go on the left, the expression on the right, no
> parentheses required. For example:
>
> > ((x : + x 1) 1)
> 2
> > ((x y : + x y) 1 2)
> 3
> > (map (x : string-upcase x) '("a" "b" "c"))
> '("A" "B" "C")
>
> ## Math Procedures
>
> Since this library uses > for function composition, the built in
> greater-than procedure is renamed to `gt?`. Note, this could break existing
> code if you are already using the > procedure. Other math procedures are
> also renamed for consistency, and because the text versions read more
> naturally when using function composition.
>
> > gt?
> < lt?
> >= gte?
> <= lte?
> + add
> - subtract
> * multiply
> / divide
>
> ## Convenience Procedures
>
> *fluent* works best when the data (input) parameter comes first. Most
> racket functions do this out of the box, but many functions which take a
> procedure as a parameter put the data last. That's fine, because you can
> just use >>. Alternatively you can wrap and rename the procedure, which is
> what we've done for these functions:
>
> original   data-first version
> -
> for-each   iterate
>
> example:
>
> > ('(1 2 3) → iterate (x : displayln x))
> 1
> 2
> 3
>
> ## Comparison to Clojure's Threading Macro
>
> Clojure's threading macro is a prefix operator, which means it is less
> readable when nested and requires more parentheses. You could say that the
> *fluent* infix operator acts as one parenthesis. Compare:
>
> CLOJURE (prefix):
>
> (-> (list (-> (-> id3 (hash-ref 'genre "unknown")) normalise-field)
>   (-> (-> id3 (hash-ref 'track "0")) normalise-field)
>   (-> (-> id3 (hash-ref 'artist "unknown")) normalise-field)
>   (-> (-> id3 (hash-ref 'title "unknown")) normalise-field))
> (string-join "."))
>
> FLUENT (infix):
>
> (list (id3 → hash-ref 'genre "unknown" → normalise-field)
>   (id3 → hash-ref 'track "0" → normalise-field)
>   (id3 → hash-ref 'artist "unknown" → normalise-field)
>   (id3 → hash-ref 'title "unknown" → normalise-field)) →
> string-join ".")
>
> Fluent's infix approach also makes it easier to combine thread-first (→)
> with thread-last (→→).
>
> ## How to enter → with your keyboard
>
> → is Unicode character 2192. On linux you can enter this using
> `shift-ctrl-u 2192 enter`. Naturally, if you want to use this character,
> you should map it to some unused key on your keyboard. This can be done
> with xmodmap:
>
> # use xev to get the keycode
> $ xev
>
> # check the current mapping
> $ xmodmap -pke
>
> # replace the mapping
> $ xmodmap -e "keycode 51=U2192 

Re: [racket-users] "Unbound Identifier" (Lists)

2021-02-25 Thread David Storrs
On Thu, Feb 25, 2021 at 12:43 PM IF Karona  wrote:

> Your solution is so elegant. Thank you!
>
> >> PS  Do I have the salutation right?  Is it 'Hello, IF' or 'Hello,
> Karona'? <<
>
> You may call me Karona. Thank you for asking. :)
>
> Karona
>
>
Cool, good to know and I'm glad you liked the solution.

Thinking more about it, it would be better to pull the match out in order
to have clearer code, and add a way to end the loop. Something like this:

#lang racket
(struct message (str sender recipient) #:transparent)
; This returns a list consisting of the message that we are sending

; out followed by the message that the participant posted. It will

; be appended to the history.

(define (say m str)
  (displayln str)
  (list (message str "me" "participant") m))

(define (find-response input history)
  (match (message-str input)
[(regexp #rx"(?i:Hello,* world!)")
 (say input "I would not know about the rest of the world, but I can
hear \
you just fine.")]
[(regexp #px"(?i:I( am|'m) learning how to program in Racket,* world!)")
 (say input "Racket is a great language, and it is lovely that you are
\
learning it, but does literally everyone need to know?")]
[(regexp #px".*,+\\s*world!")
 (say input "Did the whole world really need to hear that?")]
["DEBUG" (pretty-print history) '()]
[else (say input "I didn't understand that")]))

(let loop ([history '()])
  (display "Input: ")
  (define input  (message (read-line (current-input-port) 'any)
"participant" "me"))
  (display "Chatbot: ")
  (if (equal? (message-str input) "DONE")
  (begin (displayln "Bye!") (pretty-print history))
  (loop (append (find-response input history) history


> On Wed, Feb 24, 2021 at 11:14 PM David Storrs 
> wrote:
>
>> Hi IF,
>>
>> I think this is what you want.  You were right about the issue -- you
>> were consing onto the history list but then immediately throwing away the
>> result because it wasn't modifying the original history value.
>>
>> #lang racket
>>
>> (struct message (str sender recipient) #:transparent)
>> ; This returns a list consisting of the message that we are sending
>>
>> ; out; followed by the message that the participant posted. It will
>>
>> ; be appended; to the history.
>>
>> (define (say m str)
>>   (displayln str)
>>   (list (message str "me" "participant") m))
>>
>> ; start off with an empty history
>> (let loop ([history '()])
>>   (display "Input: ")
>>   (define input  (message (read-line (current-input-port) 'any)
>> "participant" "me"))
>>   (display "Chatbot: ")
>>   (loop
>>(append
>> (match (message-str input)
>>   [(regexp #rx"(?i:Hello,* world!)")
>>(say input "I would not know about the rest of the world, but I
>> can hear \
>> you just fine.")]
>>   [(regexp #px"(?i:I( am|'m) learning how to program in Racket,*
>> world!)")
>>(say input "Racket is a great language, and it is lovely that you
>> are \
>> learning it, but does literally everyone need to know?")]
>>   [(regexp #px".*,+\\s*world!")
>>(say input "Did the whole world really need to hear that?")]
>> ; if your input is DEBUG then it will print out the history but not add
>> to it
>>   ["DEBUG" (pretty-print history) '()]
>> ; if you type something unrecognized it will say so
>>   [else (say input "I didn't understand that")])
>> history))
>>   (loop))
>>
>>
>> PS  Do I have the salutation right?  Is it 'Hello, IF' or 'Hello, Karona'?
>>
>>
>>
>> On Wed, Feb 24, 2021 at 6:21 PM IF Karona  wrote:
>>
>>> Thank you!
>>>
>>> I can get the code that follows to run, but the chatbot never replies. I
>>> surmise this is because lists are not mutable.
>>>
>>> With the background I have the most obvious way forward would be to use
>>> an array instead of a list, but that does not strike me as the best
>>> approach to take while trying to learn functional programming.
>>>
>>> Is there a better way through this?
>>>
>>> ;example.rkt
>>>
>>> #lang racket
>>>
>>> (require racket/match)
>>>
>>> (struct message (str sender recipient))
>>>
>>> (define chat-history (list (message "" "" "&

Re: [racket-users] "Unbound Identifier" (Lists)

2021-02-24 Thread David Storrs
Hi IF,

I think this is what you want.  You were right about the issue -- you were
consing onto the history list but then immediately throwing away the result
because it wasn't modifying the original history value.

#lang racket

(struct message (str sender recipient) #:transparent)
; This returns a list consisting of the message that we are sending

; out; followed by the message that the participant posted. It will

; be appended; to the history.

(define (say m str)
  (displayln str)
  (list (message str "me" "participant") m))

; start off with an empty history
(let loop ([history '()])
  (display "Input: ")
  (define input  (message (read-line (current-input-port) 'any)
"participant" "me"))
  (display "Chatbot: ")
  (loop
   (append
(match (message-str input)
  [(regexp #rx"(?i:Hello,* world!)")
   (say input "I would not know about the rest of the world, but I can
hear \
you just fine.")]
  [(regexp #px"(?i:I( am|'m) learning how to program in Racket,*
world!)")
   (say input "Racket is a great language, and it is lovely that you
are \
learning it, but does literally everyone need to know?")]
  [(regexp #px".*,+\\s*world!")
   (say input "Did the whole world really need to hear that?")]
; if your input is DEBUG then it will print out the history but not add to
it
  ["DEBUG" (pretty-print history) '()]
; if you type something unrecognized it will say so
  [else (say input "I didn't understand that")])
history))
  (loop))


PS  Do I have the salutation right?  Is it 'Hello, IF' or 'Hello, Karona'?



On Wed, Feb 24, 2021 at 6:21 PM IF Karona  wrote:

> Thank you!
>
> I can get the code that follows to run, but the chatbot never replies. I
> surmise this is because lists are not mutable.
>
> With the background I have the most obvious way forward would be to use an
> array instead of a list, but that does not strike me as the best approach
> to take while trying to learn functional programming.
>
> Is there a better way through this?
>
> ;example.rkt
>
> #lang racket
>
> (require racket/match)
>
> (struct message (str sender recipient))
>
> (define chat-history (list (message "" "" "")))
>
> (define (say m)
>   (cons m chat-history))
>
> (define (log m)
>   (cons m chat-history))
>
> (let loop ()
>   (display "Input: ")
>   (define input (message (read-line (current-input-port) 'any)
> "participant" "me"))
>   (define str (message-str input))
>   (log input)
>
>   (cond
>
> [(regexp-match #px"(?i:Hello,* world!)" str)
>  (say (message "I would not know about the rest of the world, but I
> can hear \
> you just fine." "me" "participant"))]
>
> [(regexp-match #px"(?i:I( am|'m) learning how to program in Racket,*
> world!)" str)
>  (say (message "Racket is a great language, and it is lovely that you
> are \
> learning it, but does literally everyone need to know?" "me"
> "participant"))]
>
> [(regexp-match #px".*,+\\s*world!" str)
>  (say (message "Did the whole world really need to hear that?" "me"
> "participant"))]
>
> [else (say (message "Did you really just say something without
> addressing the \
> world? I am so proud of you! :,)" "me" "participant"))])
>
>   (define head (first chat-history))
>   (define response (message-str head))
>   (printf "Chatbot: ~a\n" response)
>   (loop))
>
> On Wed, Feb 24, 2021 at 3:11 PM George Neuner 
> wrote:
>
>>
>> Hi,
>>
>> Presumably you are using 'head' to get the first element of a list.
>> However, there is no function 'head' for lists.
>> see:  https://docs.racket-lang.org/reference/pairs.html
>>
>> Try using 'first' and 'rest' instead of 'head' and 'tail'.
>>
>> George
>>
>>
>> On 2/24/2021 3:55 PM, IF Karona wrote:
>>
>> Hi everyone,
>>
>> After trying to implement some changes Sage suggested (all errors are my
>> own), I am now encountering the following message (courtesy of DrRacket):
>>
>> "head: unbound identifier in: head"
>>
>> Could someone help me find a fix?
>>
>> As before, I welcome suggestions on how to better do this the functional
>> programming way.
>>
>> Karona
>>
>> ;example.rkt
>>
>> #lang racket
>>
>> (require racket/match)
>>
>> (struct message (str sender recipient))
>>
>> (define (say chat-history m)
>>   (cons m
>> chat-history))
>>
>> (define (log chat-history m)
>>   (cons m
>> chat-history))
>>
>> (let loop ()
>>   (display "Input: ")
>>   (define input (message (read-line (current-input-port) 'any)
>> "participant" "me"))
>>   (define str (message-str input))
>>   (log chat-history input)
>>
>>   (cond
>>
>> [(regexp-match #px"(?i:Hello,* world!)" str)
>>  (say chat-history (message "I would not know about the rest of the
>> world, but I can hear \
>> you just fine." "me" "participant" "me" "participant"))]
>>
>> [(regexp-match #px"(?i:I( am|'m) learning how to program in Racket,*
>> world!)" str)
>>  (say chat-history (message "Racket is a great language, and it is
>> lovely that you are \
>> learning it, but does literally 

Re: [racket-users] Verifying the contract on a function

2021-02-24 Thread David Storrs
Aha.  That and contract-equivalent? do what I need.  Thanks, Sam.

On Wed, Feb 24, 2021 at 10:20 PM Sam Tobin-Hochstadt 
wrote:

> You can use the value-contract function, along with contract-stronger? to
> do this.
>
> Sam
>
> On Wed, Feb 24, 2021, 6:03 PM David Storrs  wrote:
>
>> I have some macros that generate functions.  For testing purposes, I'd
>> like to be able to ask the function "Do you have this contract
>> ?"  Is there a way to do that?  I've been digging through the
>> Contracts section and googled for it but I'm not seeing one.
>>
>> --
>> 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/CAE8gKodrApnAtr%3D5BpvSLxiKAAQJjO2bj7HkE_75-VLb25rNgA%40mail.gmail.com
>> <https://groups.google.com/d/msgid/racket-users/CAE8gKodrApnAtr%3D5BpvSLxiKAAQJjO2bj7HkE_75-VLb25rNgA%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
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/CAE8gKofHrC8c5Li1eEv16DPJ3cC0frsn1Y7pieWDp-ur9mn8wA%40mail.gmail.com.


[racket-users] Verifying the contract on a function

2021-02-24 Thread David Storrs
I have some macros that generate functions.  For testing purposes, I'd like
to be able to ask the function "Do you have this contract ?"  Is
there a way to do that?  I've been digging through the Contracts section
and googled for it but I'm not seeing one.

-- 
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/CAE8gKodrApnAtr%3D5BpvSLxiKAAQJjO2bj7HkE_75-VLb25rNgA%40mail.gmail.com.


[racket-users] Match: non-greedy, and also repeated elements?

2020-12-30 Thread David Storrs
First off, is there a way to make ... in a pattern match non-greedily?
i.e., match as *few* elements as possible instead of as many?

Second, is there a way to make one pattern refer to an earlier pattern in
the same match clause?  Semi-regularly I find myself wanting to do
something like 'match repeated elements' or 'match if items from these two
lists match'.  For example:

(match (list '(a b c) '(d e c))
  [(list (list _ ... x) (list _ ... y))
   #:when (equal? x y)
   'ok]
  [else 'nope])
=> 'ok

(match '(a b c c d)
  [(list _ ... x y _ ...)
   #:when (equal? x y)
   'ok]
  [else 'nope])
=> 'ok

Is there a way to do this without needing a #:when clause?

-- 
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/CAE8gKoe78-7sBjHu%3DoR6kg4t4xqaTXjOAa1bHoE_G%2BZKpW6%3DTw%40mail.gmail.com.


Re: [racket-users] Unsafe structs

2020-12-21 Thread David Storrs

The struct-plus-plus module also provides reflection, so you might take a
look to see if there are any ideas in there that would be useful for your
own module.  Accessors are included, as are constructors, rules, wrappers,
default values, and predicates.  spp has two primary limitations:  You
cannot use a base type and you cannot mark individual fields mutable, only
the entire struct.

https://docs.racket-lang.org/struct-plus-plus/index.html#%28part._.Reflection%29


On Sun, Dec 20, 2020 at 3:34 PM Dominik Pantůček <
dominik.pantu...@trustica.cz> wrote:

> Hello Racketeers,
>
> there were some discussions about structs' introspection on the IRC
> lately and one of the questions that arose was how to get field index
> for arbitrary struct's arbitrary field.
>
> Not that it is possible... But the general discussion made me think
> about why there are no unsafe variants for structs' accessors and mutators.
>
> And given my work on some performance-demanding projects I started
> testing unsafe-struct*-ref and unsafe-struct*-set! in one of my
> simulations (yes, that raycasting/raytracing project). It bumped the
> speed from roughly 110-120 fps to about 140-150 fps on my laptop. So
> definitely worth the try.
>
> But unsafe-struct*-ref/set! degrade structs basically to strange
> vectors. And also - in my code I use struct hierarchy to decide what to
> do with different kinds of data.
>
> It didn't take long and my unsafe-struct[1] proof-of-concept was created.
>
> The code is still a bit messy. However it keeps all the semantics of
> structs and enables usage of unsafe accessors and mutators without any
> hassle. Basically the unsafe-struct and unsafe-struct-out are drop-in
> replacements or struct and struct-out.
>
> A typical usage would be:
>
> (unsafe-struct my-struct (a b (c #:mutable)) #:transparent)
> (define my-val (my-struct 1 2 3))
> (unsafe-set-my-struct-a! my-val 4)
> (displayln (unsafe-my-struct-b my-val))
>
> Of course, the procedures are inherently unsafe ...
>
> In a typical scenario I am using these immediately after checking the
> type of given value using the struct predicate (like my-struct? in this
> case) and getting the performance boost without any real un-safety.
>
> And now some questions (I bet you knew I will have some):
>
> 1) Is there anyone else reading this that could actually leverage these
> unsafe-structs for something useful?
>
> 2) If yes, what do you miss there before I create a package from the
> code? (Yes, scribblings, yes, slightly cleaning the code up - but what
> else?)
>
> 3) In the syntax pattern I was unable to create a sub-pattern to get the
> field-mutable for all fields (including those without any field options)
> - that's the reason for most of the long let* later on. Is there a
> better way? (I will think about this one, but more eyes ...)
>
>
> Cheers,
> Dominik
>
> P.S.: I didn't abandon the flalgebra module, I am actually working on
> another approach that should move the resulting "DSL" closer to the
> flonums unboxing and register allocation code. More on that later.
>
>
> [1] https://gitlab.com/racketeer/unsafe-struct
>
> --
> 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/90b3e86a-db1d-c658-111b-ae4010c5bea2%40trustica.cz
> .
>

-- 
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/CAE8gKoeJHs9Pg%3DvMn%2BzP9V-1CEdv0kU26A7sRMa1E0mV3E0eLQ%40mail.gmail.com.


Re: [racket-users] I‘m new to racket, i want to know the best resources of learning racket

2020-12-04 Thread David Storrs
There's also the Racket Guide:  https://docs.racket-lang.org/guide/

On Thu, Dec 3, 2020 at 8:45 PM Yi Chen  wrote:

> Haha, that's for sure. Thanks your suggestion!
> Have a nice day:-)
>
> 在2020年12月4日星期五 UTC+8 上午5:53:36 写道:
>
>> On Thu, Dec 03, 2020 at 02:19:43AM -0800, Yi Chen wrote:
>> > Any suggestions? Thanx for you guys
>>
>> Start with How To Design Programs., which is available as a free .pdf.
>> By the time that bores you, you'll likely have found other resources.
>>
>> -- hendrik
>>
>> >
>> > --
>> > 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...@googlegroups.com.
>> > To view this discussion on the web visit
>> https://groups.google.com/d/msgid/racket-users/0968f9d2-e546-4908-b744-a7e26e5a7ed1n%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/75575ec4-f169-4b0b-aa70-06acd5d7d0den%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/CAE8gKofOm1Ca59-DVAD4DeLOdWbTOPeBLjcaf-zcynO%2BF00Lew%40mail.gmail.com.


Re: [racket-users] Unusable mail group

2020-11-30 Thread David Storrs
(cc'ing list because this might help others)

Note that you can set your gmail account to forward some or all of your
email to another account, even one that is not gmail.  It's a useful way to
aggregate things.

On Sun, Nov 29, 2020 at 10:42 PM Albert Wagner  wrote:

> Yes, thank you, John.  I'm sorry to have bothered you.  I have a google
> account but I never really go there.  I think that I have it all
> straightened out now.
>
> On Sunday, November 29, 2020 at 2:52:09 PM UTC-6 johnbclements wrote:
>
>> It looks to me like there is a “My membership settings” pane in the left
>> of the google groups web interface that allows you to specify the “email
>> used for membership”. I conjecture that this would control the delivery of
>> group e-mails. I also strongly suspect that this will only allow you to
>> choose from the e-mail addresses associated with your gmail account
>> (though, to be clear, these do *not* have to be gmail addresses). It’s not
>> clear to me from your e-mail whether logging into your gmail account in
>> order to use the web interface is something that you’re willing or able to
>> do.
>>
>> Does this help at all?
>>
>> John
>>
>>
>> > On Nov 28, 2020, at 8:00 PM, Albert Wagner  wrote:
>> >
>> > My actual email address is: albert...@mail.com, NOT the email above in
>> "From"
>> > I don't use my gmail account.
>> > I can find no way to change my email account in this URL:
>> > https://groups.google.com/g/racket-users
>> >
>> > --
>> > 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...@googlegroups.com.
>> > To view this discussion on the web visit
>> https://groups.google.com/d/msgid/racket-users/cf97db2a-9a38-4a72-bc7a-38a325e3b190n%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/c6365115-2481-4ba3-a43e-18e654e26e86n%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/CAE8gKof98vdk-S2unGznyhDXvB8V29Xz3p0Gczo10heju1dX0Q%40mail.gmail.com.


Re: [racket-users] Help implementing an early return macro

2020-10-28 Thread David Storrs
I'm not sure if this is exactly what you want, but the handy module (which
I still need to split up into less of a Fibber McGee) includes handy/try.
This would let you do the following:

#lang racket

(require handy/try)

(define x (random 100))

; these are obviously silly functions that are only for the sake of example
(define (fails-first-check? x)   (= 0 (modulo x 10)))
(define (fails-second-check? x)  (= 0 (modulo x 7)))
(define (calculate-final-result z) 'final-result)

(displayln
 (try [(displayln (~a "x is: " x))
   (when (fails-first-check? x) (raise 'failed-first-check))
   (when (fails-second-check? x) (raise 'failed-second-check))
   (define z 'z)
   ; ...do something with z

   (calculate-final-result z)]
  [catch
((curry equal? 'failed-first-check)   (lambda (e) "failure #1"))
((curry equal? 'failed-second-check)  (lambda (e) "failure #2"))
(any/c(lambda (e)
'last-chance-processing-here))]))

It also supports pre and post checks:

#lang racket

(require handy/try)

(define x (random 100))

; real code would do something more sensible

(define (fails-first-check? x) (= 0 (modulo x 10)))
(define (fails-second-check?x) (= 0 (modulo x 7)))
(define (calculate-final-result z) 'final-result)

(displayln
 (try [pre (displayln "pre checks are guaranteed to happen")]
  [(displayln (~a "x is: " x))
   (when (fails-first-check? x) (raise 'failed-first-check))
   (when (fails-second-check? x) (raise 'failed-second-check))
   (define z 'z)
   ; ...do something with z

   (calculate-final-result z)]
  [catch
  ((curry equal? 'failed-first-check)   (lambda (e) "failure #1"))
  ((curry equal? 'failed-second-check)  (lambda (e) "failure #2"))
  (any/c(lambda (e)
'last-chance-processing-here))]
  [finally
   (displayln "do final cleanup here -- delete temp files, close
sockets, etc")
   (displayln "this is guaranteed to run even if an uncaught exception
is raised")
   ]))

The main body is required but 'pre', 'catch', and 'finally' are all
optional.  The whole thing is a dynamic-wind wrapped around a with-handlers
so pre and finally are guaranteed to execute no matter what.  pre is out of
scope for the main body which is suboptimal but if there was interest then
I might see about fixing that.

Unfortunately, like many of the submodules in handy 'try' has extensive
documentation in the comments but not in Scribble.  Again, I should get
around to that in my Copious Free Time.  For now, it's here:
https://github.com/dstorrs/racket-dstorrs-libs/blob/master/try.rkt



On Wed, Oct 28, 2020 at 9:48 AM Hendrik Boom  wrote:

> On Wed, Oct 28, 2020 at 03:54:29AM -0700, Jack Firth wrote:
> > So I'm a little tired of writing code like this:
> >
> > (define x ...)
> > (cond
> >   [(take-shortcut? x) (shortcut x)]
> >   [else
> >(define y (compute-y x))
> >(cond
> > [(take-other-shortcut? x y) (other-shortcut x y)]
> > [else
> >  (define z ...)
> >  (cond ...)])])
>
> Perhaps you could use parendown
> https://docs.racket-lang.org/parendown/index.html
>
> #lang parendown racket/base
> (define x ...)
> (cond
>   [(take-shortcut? x) (shortcut x)]
>   #/ else
>   (define y (compute-y x))
>   #/ cond
>   [(take-other-shortcut? x y) (other-shortcut x y)]
>   #/ else
>   (define z ...)
>   #/ cond ...
> )
>
> >
> > That is,
> Frequently the lase element of a list is another list, and a large one
> at that.
> Using #/ makes that a kind of tail-recursive syntax and eliminates some
> explicit parentheses.
>
> Of course when you start using this it becomes so common that you'd like
> to drop the ugly #'s, but unfortunately, / is already taken.
>
> -- hendrik
>
> --
> 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/20201028134830.54plnv6nv5j3lcmt%40topoi.pooq.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/CAE8gKodfdWieNE2iYqOO-Jajqv3E-%2B8MUhV-%2BwhPkShUvYouXA%40mail.gmail.com.


Re: [racket-users] [scribble] Are nested lists possible?

2020-10-13 Thread David Storrs
On Tue, Oct 13, 2020 at 6:52 PM William J. Bowman 
wrote:

> > >>> @defproc[(trie-add-item+data! [arg trie?][item (listof
> any/c)][#:combine
> Is the issue that you rebound `item`?
>
>
...

Yes.  Yes, that is exactly the issue.  I hate my life.

Thank you.


On Tue, Oct 13, 2020 at 10:20:24AM -0700, Sorawee Porncharoenwase wrote:
> > apparently it doesn’t like having an itemlist inside of a {} block at all
> >
> > I’m not sure if I totally understand it, but this doesn’t appear to be
> > true. The below doc renders correctly as I expect.
> >
> > #lang scribble/manual
> >
> > @itemlist[
> >   @item{foo
> > @itemlist[
> >   @item{bar}
> >   @item{baz}]
> > hello
> > @itemlist[
> >   @item{world}]}
> >  @item{foo2
> > @itemlist[
> >   @item{bar2}
> >   @item{baz2}]
> > hello2
> > @itemlist[
> >   @item{world2}]}]
> >
> >
> > On Tue, Oct 13, 2020 at 10:09 AM David Storrs 
> > wrote:
> >
> > > Okay, apparently it doesn't like having an itemlist inside of a {}
> block
> > > at all, but as long as it's outside of one then nested lists are fine.
> > > Ugh.  I know Scribble is super good because it makes beautiful
> > > documentation and does cross-linking and examples and all that, but
> it's
> > > also a complete pain in the ass unless you're expert with it.
> > >
> > > Sorry for wasting everyone's time.
> > >
> > > On Tue, Oct 13, 2020 at 1:02 PM David Storrs 
> > > wrote:
> > >
> > >> Argh.  Wrong code.  Please ignore prior message.
> > >>
> > >> On Tue, Oct 13, 2020 at 12:57 PM David Storrs  >
> > >> wrote:
> > >>
> > >>>
> > >>>
> > >>> On Tue, Oct 13, 2020 at 12:48 PM Ben Greenman <
> > >>> benjaminlgreen...@gmail.com> wrote:
> > >>>
> > >>>> On 10/13/20, David Storrs  wrote:
> > >>>> > @itemlist[
> > >>>> >   @item{The size cage needed depends on the type of dog
> > >>>> >   @itemlist[
> > >>>> > @item{Pug:  Small}
> > >>>> > @item{Collie: Medium}
> > >>>> > @item{Mastiff:  Large}]}]
> > >>>> >
> > >>>> > I would like to produce something that looks like this:
> > >>>> >
> > >>>> >- The size cage needed depends on the type of dog
> > >>>> >   - Pug: Small
> > >>>> >   - Collie: Medium
> > >>>> >   - Mastiff: Large
> > >>>> >
> > >>>> > Is there a correct way to do this?
> > >>>>
> > >>>> What you have looks good to me in #lang scribble/manual
> > >>>>
> > >>>>
> > >>> Here's the actual code:
> > >>>
> > >>> @defproc[(trie-add-item+data! [arg trie?][item (listof
> any/c)][#:combine
> > >>> combine-method (or/c 'keep 'replace 'meld/current 'meld/new (->
> trie-node?
> > >>> trie-node? trie-node?)) 'meld/new]) trie?]{Adds one item to the trie
> where
> > >>> the elements of the list are considered to be elements of the item.
> If an
> > >>> item is a @racket[cons] pair where the @racket[cdr] is a
> > >>> @racket[trie-node?] then the @racket[car] will be used as the
> element and
> > >>> the @racket[cdr] will be the data attached to that node.  The final
> node is
> > >>> marked as terminal regardless of whether it already existed.
> > >>>
> > >>> If an element of the item already exists in the trie then that
> element
> > >>> will be updated based on the combine method specified via the
> > >>> @racket[#:combine] keyword.  Specifically:
> > >>>
> > >>> @itemlist[
> > >>> @item{test}
> > >>> ]
> > >>> }
> > >>>
> > >>> Here's the error output:
> > >>>
> > >>> trie.scrbl:165:0: item: misuse of an identifier (not in `racket',
> etc.)
> > >>> that is bound as a code-typesetting variable
> > >>>   in: (item "test")
> > >>>   location...:
> > >>>trie.scrbl:165:0
> > >>>   context...:
> > >>>do

Re: [racket-users] [scribble] Are nested lists possible?

2020-10-13 Thread David Storrs
Okay, apparently it doesn't like having an itemlist inside of a {} block at
all, but as long as it's outside of one then nested lists are fine.  Ugh.
I know Scribble is super good because it makes beautiful documentation and
does cross-linking and examples and all that, but it's also a complete pain
in the ass unless you're expert with it.

Sorry for wasting everyone's time.

On Tue, Oct 13, 2020 at 1:02 PM David Storrs  wrote:

> Argh.  Wrong code.  Please ignore prior message.
>
> On Tue, Oct 13, 2020 at 12:57 PM David Storrs 
> wrote:
>
>>
>>
>> On Tue, Oct 13, 2020 at 12:48 PM Ben Greenman <
>> benjaminlgreen...@gmail.com> wrote:
>>
>>> On 10/13/20, David Storrs  wrote:
>>> > @itemlist[
>>> >   @item{The size cage needed depends on the type of dog
>>> >   @itemlist[
>>> > @item{Pug:  Small}
>>> > @item{Collie: Medium}
>>> > @item{Mastiff:  Large}]}]
>>> >
>>> > I would like to produce something that looks like this:
>>> >
>>> >- The size cage needed depends on the type of dog
>>> >   - Pug: Small
>>> >   - Collie: Medium
>>> >   - Mastiff: Large
>>> >
>>> > Is there a correct way to do this?
>>>
>>> What you have looks good to me in #lang scribble/manual
>>>
>>>
>> Here's the actual code:
>>
>> @defproc[(trie-add-item+data! [arg trie?][item (listof any/c)][#:combine
>> combine-method (or/c 'keep 'replace 'meld/current 'meld/new (-> trie-node?
>> trie-node? trie-node?)) 'meld/new]) trie?]{Adds one item to the trie where
>> the elements of the list are considered to be elements of the item.  If an
>> item is a @racket[cons] pair where the @racket[cdr] is a
>> @racket[trie-node?] then the @racket[car] will be used as the element and
>> the @racket[cdr] will be the data attached to that node.  The final node is
>> marked as terminal regardless of whether it already existed.
>>
>> If an element of the item already exists in the trie then that element
>> will be updated based on the combine method specified via the
>> @racket[#:combine] keyword.  Specifically:
>>
>> @itemlist[
>> @item{test}
>> ]
>> }
>>
>> Here's the error output:
>>
>> trie.scrbl:165:0: item: misuse of an identifier (not in `racket', etc.)
>> that is bound as a code-typesetting variable
>>   in: (item "test")
>>   location...:
>>trie.scrbl:165:0
>>   context...:
>>do-raise-syntax-error
>>apply-transformer-in-context
>>apply-transformer
>>dispatch-transformer
>>for-loop
>>[repeats 2 more times]
>>finish-bodys
>>lambda-clause-expander
>>for-loop
>>[repeats 1 more time]
>>finish-bodys
>>for-loop
>>finish-bodys
>>loop
>>for-loop
>>[repeats 3 more times]
>>
>>
>> It works fine if I remove the inner @itemlist.  What should I do
>> differently?
>>
>> --
>>> 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/CAFUu9R4-4BO3Gi2PDxZ%3D2BbQCrJP4O%2BkAWT1f7DJJtFapFdYTA%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/CAE8gKocp9RQ0cV1OL1dAAH%2B4CevDVTfHvd8Xf5o%3DP5KGeUZwjg%40mail.gmail.com.


Re: [racket-users] [scribble] Are nested lists possible?

2020-10-13 Thread David Storrs
Argh.  Wrong code.  Please ignore prior message.

On Tue, Oct 13, 2020 at 12:57 PM David Storrs 
wrote:

>
>
> On Tue, Oct 13, 2020 at 12:48 PM Ben Greenman 
> wrote:
>
>> On 10/13/20, David Storrs  wrote:
>> > @itemlist[
>> >   @item{The size cage needed depends on the type of dog
>> >   @itemlist[
>> > @item{Pug:  Small}
>> > @item{Collie: Medium}
>> > @item{Mastiff:  Large}]}]
>> >
>> > I would like to produce something that looks like this:
>> >
>> >- The size cage needed depends on the type of dog
>> >   - Pug: Small
>> >   - Collie: Medium
>> >   - Mastiff: Large
>> >
>> > Is there a correct way to do this?
>>
>> What you have looks good to me in #lang scribble/manual
>>
>>
> Here's the actual code:
>
> @defproc[(trie-add-item+data! [arg trie?][item (listof any/c)][#:combine
> combine-method (or/c 'keep 'replace 'meld/current 'meld/new (-> trie-node?
> trie-node? trie-node?)) 'meld/new]) trie?]{Adds one item to the trie where
> the elements of the list are considered to be elements of the item.  If an
> item is a @racket[cons] pair where the @racket[cdr] is a
> @racket[trie-node?] then the @racket[car] will be used as the element and
> the @racket[cdr] will be the data attached to that node.  The final node is
> marked as terminal regardless of whether it already existed.
>
> If an element of the item already exists in the trie then that element
> will be updated based on the combine method specified via the
> @racket[#:combine] keyword.  Specifically:
>
> @itemlist[
> @item{test}
> ]
> }
>
> Here's the error output:
>
> trie.scrbl:165:0: item: misuse of an identifier (not in `racket', etc.)
> that is bound as a code-typesetting variable
>   in: (item "test")
>   location...:
>trie.scrbl:165:0
>   context...:
>do-raise-syntax-error
>apply-transformer-in-context
>apply-transformer
>dispatch-transformer
>for-loop
>[repeats 2 more times]
>finish-bodys
>lambda-clause-expander
>for-loop
>[repeats 1 more time]
>finish-bodys
>for-loop
>finish-bodys
>loop
>for-loop
>[repeats 3 more times]
>
>
> It works fine if I remove the inner @itemlist.  What should I do
> differently?
>
> --
>> 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/CAFUu9R4-4BO3Gi2PDxZ%3D2BbQCrJP4O%2BkAWT1f7DJJtFapFdYTA%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/CAE8gKoeGQ3BA-qUbNhWJebPV4%2BaLf7_9xJkcFFvRK-dDx%3Duj0w%40mail.gmail.com.


Re: [racket-users] [scribble] Are nested lists possible?

2020-10-13 Thread David Storrs
On Tue, Oct 13, 2020 at 12:48 PM Ben Greenman 
wrote:

> On 10/13/20, David Storrs  wrote:
> > @itemlist[
> >   @item{The size cage needed depends on the type of dog
> >   @itemlist[
> > @item{Pug:  Small}
> > @item{Collie: Medium}
> > @item{Mastiff:  Large}]}]
> >
> > I would like to produce something that looks like this:
> >
> >- The size cage needed depends on the type of dog
> >   - Pug: Small
> >   - Collie: Medium
> >   - Mastiff: Large
> >
> > Is there a correct way to do this?
>
> What you have looks good to me in #lang scribble/manual
>
>
Here's the actual code:

@defproc[(trie-add-item+data! [arg trie?][item (listof any/c)][#:combine
combine-method (or/c 'keep 'replace 'meld/current 'meld/new (-> trie-node?
trie-node? trie-node?)) 'meld/new]) trie?]{Adds one item to the trie where
the elements of the list are considered to be elements of the item.  If an
item is a @racket[cons] pair where the @racket[cdr] is a
@racket[trie-node?] then the @racket[car] will be used as the element and
the @racket[cdr] will be the data attached to that node.  The final node is
marked as terminal regardless of whether it already existed.

If an element of the item already exists in the trie then that element will
be updated based on the combine method specified via the @racket[#:combine]
keyword.  Specifically:

@itemlist[
@item{test}
]
}

Here's the error output:

trie.scrbl:165:0: item: misuse of an identifier (not in `racket', etc.)
that is bound as a code-typesetting variable
  in: (item "test")
  location...:
   trie.scrbl:165:0
  context...:
   do-raise-syntax-error
   apply-transformer-in-context
   apply-transformer
   dispatch-transformer
   for-loop
   [repeats 2 more times]
   finish-bodys
   lambda-clause-expander
   for-loop
   [repeats 1 more time]
   finish-bodys
   for-loop
   finish-bodys
   loop
   for-loop
   [repeats 3 more times]


It works fine if I remove the inner @itemlist.  What should I do
differently?

-- 
> 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/CAFUu9R4-4BO3Gi2PDxZ%3D2BbQCrJP4O%2BkAWT1f7DJJtFapFdYTA%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/CAE8gKodk0yE3rNQwakRxTyvQYC9pXQmKfzwNUM1qR2dgjB75MA%40mail.gmail.com.


[racket-users] [scribble] Are nested lists possible?

2020-10-13 Thread David Storrs
@itemlist[
  @item{The size cage needed depends on the type of dog
  @itemlist[
@item{Pug:  Small}
@item{Collie: Medium}
@item{Mastiff:  Large}]}]

I would like to produce something that looks like this:

   - The size cage needed depends on the type of dog
  - Pug: Small
  - Collie: Medium
  - Mastiff: Large

Is there a correct way to do this?

-- 
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/CAE8gKoewMoNZKdsycdFuJmOvvdtfZi%3Do0hcfK%3Dmo9DFiDkoyQg%40mail.gmail.com.


  1   2   3   4   5   6   7   8   >