Re: [racket-users] Re: Detecting broken inbound TCP connections

2022-07-01 Thread George Neuner

Hi Jeff,

Note that most network problems result in an exception ... which your 
code is not catching and which you might have missed seeing in the 
output.  You need to catch *exn:fail:network* and examine the *errno* 
field to figure out what happened. *


errno* is a cons: *( integer . symbol )*  of the error code and a symbol 
identifying the platform for which the error has meaning.  The codes are 
(somewhat) platform dependent so you will need other references to 
decode them.


For more, see:

 * 
https://docs.racket-lang.org/reference/exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn%29%29
 * 
https://docs.racket-lang.org/reference/exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3anetwork~3aerrno%29%29


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/31a25463-eb1e-2f05-920a-7cfa49e33f99%40comcast.net.


[racket-users] Re: Why does a module need an inside scope?

2022-06-08 Thread George Neuner
On Wed, 1 Jun 2022 01:14:46 -0700 (PDT),
"sym...@gmail.com"
 wrote:

>Hi, why does a module need an inside scope in addition to the outside 
>scope? What will break if the inside scope is removed?

Hi,

Most discussion of Racket has moved to the discourse group.  
https://racket.discourse.group/

These newsgroups still may be monitored, but you will likely get your
questions answered faster in the discourse.

-- 
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/vdd1ahh9npoenoj2n5bdj7i6npndrf6cro%404ax.com.


[racket-users] Re: Surprising but convenient

2021-12-19 Thread George Neuner
On Sun, 19 Dec 2021 17:50:11 +0100, Jacob Jozef
 wrote:

>I start a thread printing a file. When the file will be very long (say
>50 GB) the thread takes too much time and I kill it when it takes
>more time than I want to permit. Outside the thread I clean up.
>Closing the output-port before deleting the file takes much time. But
>to my surprise I can delete the file before closing the port, which
>hardly takes time.

It will take less time to stop the thread if you work line by line, or
in small(ish) groups of lines, and flush the output port each time you
go back for more input.

As for deleting the file, all you have done is remove the directory
entry ... the file itself won't go away until the last open handle on
it is closed.  That particular behavior /is the same/ in Windows and
Unix/Linux.


>After deleting the file, the port remains open, but writing to it does
>nothing. Correct?

No. Your program still has an open handle to the file and it is still
reading from it.  Only the file's directory entry is gone.

You need to close the open file handle in your program in order to
truly delete the file.  Depending on your code, simply killing the
thread may not do that.


>Thanks, Jos

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/2h10sgt81h7nim2ps3dfak2te00m3724hv%404ax.com.


Re: [racket-users] Possible options for stopping spam

2021-12-15 Thread George Neuner


Is there a way to whitelist / trust posters.  One of the other groups I 
follow is moderated, but is set up so that messages from trusted posters 
go straight through.  The moderator(s) only have to look at posts coming 
from untrusted sources and decide whether new posters can be trusted.


Caveat: I don't know how much effort that requires.  It just seems like 
a possible 4th option (if doable).



On 12/14/2021 10:02 PM, Sage Gerard wrote:


> Wouldn't people asking to be invited be pretty much the same 
moderation burden as option 3, but with less support? I guess that's a 
way of saying I lean to option 3.


I see what you mean. I saw "invite-only" as the option with the most 
/discretionary/ effort when volunteers are scarce, since a trusted 
member of this community can add a member with a presumably lower risk 
of introducing a spammer. Since I'm not going to be available to ban 
spammers forever, I'm reading these options in terms of minimizing the 
reasons someone has to drop what they are doing to mess with the list.


On 12/14/21 3:53 PM, David Bremner wrote:

Sage Gerard  writes:


All,

I've gained administrative privileges over this list to address the spammer. I 
want to hear from others before I touch anything.


Thanks for putting effort into this.


I've been informed that an invite-only approach might not be appropriate, but 
without moderation, the only option I see is to change the privacy settings. 
Here are the choices Google gives us.

- Invited users only
- Anyone on the web can join
- Anyone on the web can ask

Wouldn't people asking to be invited be pretty much the same moderation
burden as option 3, but with less support? I guess that's a way of
saying I lean to option 3.


Comments welcome, but note that I do not know the chain of command. If
it comes down to my judgement, please let me know.


Pretty sure I'm not in any relevant chain of command.

d


--
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/f22fdcd2-0781-4012-d906-cad44617ddc4%40comcast.net.


Re: [racket-users] Re: Discourse - Mailing list mode

2021-12-08 Thread George Neuner



On 12/8/2021 12:34 PM, James Platt wrote:

On Dec 8, 2021, at 10:45 AM, George Neuner wrote:

> It's a big deal if you are (or were) following multiple groups.

I don't understand.  Why is this an issue?  I find it very convenient to filter 
each group into it's own folder in email.  If this were a non-technical group, 
you wouldn't expect everyone to know how to do that but anyone who is a 
programmer ought to have no problem configuring filters and folders.


If you had continued reading, you would have seen my comment that NOT 
ALL news groups support list distribution or posting via email. NNTP is 
not email.  Usenet group moderators[*] can choose how to make their 
groups available: the default is via list distribution and NNTP both, 
but the moderator can deliberately disable one or the other - or only 
enable digests via email, or disable posting.


My complaint is having to read some things via NNTP and others through 
email because, while there are programs that do both, I haven't found 
any single program that does BOTH WELL.  And that is without even 
considering the growing number of ... don't want to confuse by saying 
"groups", let's call them "crowds" ... that have abandoned Usenet 
entirely in favor of web forums.


George

[*] even unmoderated groups have a moderator/administrator - by default 
it is whoever started the group.



--
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/5f17-59b4-a381-ddd7-25b435887694%40comcast.net.


[racket-users] Re: Discourse - Mailing list mode

2021-12-08 Thread George Neuner
On Tue, 7 Dec 2021 17:56:38 -0500, James Platt
 wrote:

> I notice that Discourse has a "mailing list mode"  which you can set
> in the preferences.  I haven't had a chance to evaluate it much yet
> but, what I'm hoping for is that this will allow me to use the forum
> pretty much the same way as I have been using Google Groups all
> along.  I just realized, after catching up with some older messages
> on this list, that I have been presuming, thus far, that the whole
> point of Discourse was to have basically the same functionality as
> Google Groups from the standpoint of managing the email list but also
> have different (hopefully better) features at the server/web site
> end.   Are others not seeing it this way?  List mode is not default
> so you do have to explicitly go in and set it.  With Google Groups,
> list mode is default but you can turn that off and only read messages
> on the server.   So I'm not seeing this change as that much of a big
> deal unless I'm wrong about the email end for Discourse

It's a big deal if you are (or were) following multiple groups.

In the last ~10 years, a lot of the old groups have abandoned NN for
web forums ... some due to spam in unmoderated groups, but it seems to
me mostly that the change has been driven by pandering to youngsters
who won't be caught dead using a simple text based service (except, of
course, for SMS which they can't live without).

Where once you could monitor many groups with just a news reader OR an
email client, now you need both because many mailing lists are no
longer on NNTP and many newsgroups no longer support email access. And
then you have to monitor a plethora of web forums to follow the groups
that have gone over entirely to those platforms.

So where you once had one program that handled all your news needs,
now you need 2 or 3 different programs (NN reader, web browser, maybe
separate email client).  Keeping your own archives of interesting
discussions - if you even /can/ keep archives (web forums) - has
become much more difficult and time consuming, and you have to look in
multiple places to find things.

[Yes, I use Thunderbird for email and I know it has NNTP also ... but
it can't share/sync its NN folders across multiple machines.  I don't
know of any program that does BOTH email and NNTP that /can/ sync
everything across machines.  Walking around with a USB drive is a
non-starter.]


Change for the sake of change is not a win.  I don't mind Discourse so
much because it has mailing list support, but I am bothered by the
principle.

YMMV,
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/o1i1rgd569e4vr52j4nv9kfn55h002rfv2%404ax.com.


Re: [racket-users] Anyone successfully filtering Italian spam?

2021-12-01 Thread George Neuner



On 12/1/2021 1:30 PM, Nathaniel W Griswold wrote:

> On Nov 30, 2021, at 8:22 AM, Laurent  wrote:
> 
> The last 10 spams have all these words in common:

> https://pastebin.com/BB0arV63
> and many more (which I won't copy here for obvious reasons). 
> 
> So you could create a dedicated spam filter that looks for *any* of (not: all of) these words.


I am gonna do this, actually, because i can see a few more words that are in pretty much 
all of the ones that actually get through my barriers. Judging by the google translation, 
it seems to consistently be a (very narrowly) "coherent" smear on the same 
people for the same things every time, and you have included some of the proper nouns, 
too, so this seems to be the way to go. I think it will get everything.

Thanks,

Nate



I've been dealing with this for well over 10 years reading various news 
groups.  You need to match on descriptive nouns: criminal, terrorist, 
etc.  Over time the names of the people and the descriptions of them 
will change.


If you look carefully at the Italian, you'll see the same descriptors 
come in multiple forms which change in use due to declension (parts of 
speech).  You need to match word stems rather than words:  e.g., crimi 
or crimin so you catch all the different forms of criminal .  Because 
the descriptors are nouns, you have to match them case insensitive, 
because they may or may not be capitalized depending on use.  The recent 
spam has been all caps, but that hasn't always been so.


Filtering can be done fairly easily with regex (with my NN reader has) 
once you figure out what to look for, but most email filter systems 
offer only a simple "contains" filter where you have to supply every 
possible capitalization (at least 3: none, all, and first).


Good Luck!
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/3dccf050-e34b-94c9-a967-d9057175a4e2%40comcast.net.


Re: [racket-users] Anyone successfully filtering Italian spam?

2021-11-30 Thread George Neuner



On 11/30/2021 9:22 AM, Laurent wrote:

The last 10 spams have all these words in common:
https://pastebin.com/BB0arV63
and many more (which I won't copy here for obvious reasons).

So you could create a dedicated spam filter that looks for *any* of 
(not: all of) these words.


Unfortunately, this idiot has been spamming a number of (mostly 
programming language) groups for more than 10 years now.  Every other 
month or so the subject (and hence the relevant keywords) changes, along 
with the poster's name and email address, etc.


I used to read the racket groups through NN via Gmane ... sometimes 
still do, but mostly use email now.  A few years ago Gmane changed hands 
and got flaky for a while, so I activated email delivery on the racket 
group server to be sure I was seeing all the posts. Gmane still carries 
racket, but many of the other groups it used to carry are gone.


My NN reader has several filters dedicated to this italian spam, but 
(until recently) I didn't need to filter it from my email.


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/6811d26a-b810-9ecf-f485-85774dfd7471%40comcast.net.


Re: [racket-users] Anyone successfully filtering Italian spam?

2021-11-30 Thread George Neuner



On 11/30/2021 6:57 AM, Stephen De Gabrielle wrote:
I’m using gmail for racket-users, but the normally reliable spam 
filtering fails - despite numerous attempts to train - it still 
classifies real mail as spam and the spam as real.

S.


I'm convinced that Google does that on purpose ... I believe they are 
paid to keep users looking in their spam folders.


YMMV,
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/5d9ca216-35d5-6a73-b3d4-10a49d229d09%40comcast.net.


Re: [racket-users] Anyone successfully filtering Italian spam?

2021-11-29 Thread George Neuner



On 11/29/2021 6:45 PM, Nathaniel Griswold wrote:

It’s getting through my filters, neither rspamd or my local client can catch on 
to it.

Is there a good simple filter?

Nate


Something has changed very recently because until this last week I 
rarely saw it (even marked AS spam) ... maybe a few times this whole 
year.  But in the last week I have gotten one or more copies in my inbox 
every day.


I use Thunderbird for email - which has a built-in learning junk filter 
- but I assumed my provider was filtering it because - sans a specific 
rule - Thunderbird would have just put in the Junk folder. I just wasn't 
seeing it.


???
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/a9f4c8f7-12b3-ea4c-726a-ec16c1e65eb1%40comcast.net.


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

2021-11-22 Thread George Neuner


On 11/22/2021 11:19 AM, Philip McGrath wrote:


It appears that some Gmail spam filter has decided that 
racket-users@googlegroups.com is a suspicious email address. It seems 
like roughly half of the legitimate traffic on the list is never 
reaching me and being marked as spam (at one of two or three hops on 
its way—but I have every reason to believe the situation would be as 
bad or worse for a new subscriber with a less convoluted email setup, 
especially since even mail from people I've corresponded with directly 
is being marked as spam). This seems reasonable, actually, since the 
Google Groups filters don't seem to be stopping a very high proportion 
of total traffic on the list from consisting of all-caps spam in 
Italian with some obviously-off-topic keywords.


I'm all for finding that fool who spams in Italian and giving him a 
Sicilian necktie for Christmas.


OTOH, the problems with spam filters are just more reasons to ditch 
Google and Gmail ... not necessarily the mailing list.


YMMV,
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/b540b517-f73a-8bf2-8ef4-0f19a1e14e78%40comcast.net.


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

2021-10-21 Thread George Neuner


On 10/20/2021 5:53 PM, unlimitedscolobb wrote:

I have two main use cases for producing an ordered list from a hash table:

1. A canonical way to pretty print a hash table: In my projects, I 
carry around and print out hash tables a lot, so I like the elements 
to appear in the same order all the time, whatever that order may be. 
Luckily, `hash-map` orders symbols alphabetically and numbers 
according to the natural order, so it's perfect for my use.


It's fine if it works for you.  Just beware hashing on things like 
lists, structs, objects, etc.


You might look into Laurent Orseau's "text-table" package.   Tables are 
a great way to print structured output.



2. Testing the contents of a mutable hash table: The only way I found 
to that is to convert the hash table to an ordered list and compared 
it to the test list. This is clearly not the most efficient use of a 
hash table, but I can totally go with that, since it's about testing 
and not the actual performance.


Of course, I am totally open to learning better ways of doing these 
things!


Depends on what you're trying to do.  Sometimes changing the data format 
IS the best way.  That said ...


Be aware that the code fragments below were just made up as I wrote this 
... they have not been tested and may contain unbalanced parentheses but 
they should give you the idea.  Nothing here depends on the ordering of 
data in the hashes.  Also if you prefer "do" loops to "for" loops, you 
can use them instead.


Note also the use of  "in-list", 
"in-hash-pairs","in-mutable-hash-pairs".  Racket "for" loops work with 
sequences, and although many data types - including lists and hashes - 
will implicitly ACT as sequences, explicitly using the relevant sequence 
constructors can make your "for" loops run faster.


    see https://docs.racket-lang.org/reference/sequences.html


   =


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

There is a function "hash-keys-subset?"  that checks if the keys in one 
hash are a subset of keys in another hash.  It generally will be faster 
than an equivalent loop, but it requires that both hashes use the same 
key comparison function.



To see if 2 hashes contain the same set of (k,v) pairs:

    ; immutable
    (for/and ([(k,v) (in-hash-pairs hash1)])
    (equal v (hash-ref hash2 k fail))

    ; mutable
    (for/and ([(k,v) (in-mutable-hash-pairs hash1)])
    (equal v (hash-ref hash2 k fail))



Figuring out the difference between one hash vs another is a bit harder, 
but a loop similar to the equality check works for this also:


    (for/list ([(k,v) (in-{mutable-}hash-pairs hash1)]
    #:unless (equal v (hash-ref hash2 k fail)))
   (cons k v))

Note that the ordering matters - the loop finds things that are in hash1 
but not in hash2.  Also instead of creating a list of what's missing, 
you could create another hash:


    ; create immutable hash
    (for/hash ([(k,v) (in-{mutable-}hash-pairs hash1)]
    #:unless (equal v (hash-ref hash2 k fail)))
   (values k v))

    ; update a mutable hash
    (for ([(k,v) (in-{mutable-}hash-pairs hash1)]
    #:unless (equal v (hash-ref hash2 k fail)))
   (hash-set! result k v))

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




Obviously there is a theme here.  

You are free to mix and match things: if your test data already is in 
lists, you can use the lists directly - either as the source sequences 
or as the lookup targets (since it's only a test, searching lists with 
"member" et al shouldn't matter  ).


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/3b4773bb-65a5-6783-df14-b1131b0b4a5c%40comcast.net.


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

2021-10-20 Thread George Neuner
On Wed, 20 Oct 2021 09:44:42 -0700 (PDT), Ryan Kramer
 wrote:

> :
>The other feature of let++ is that it also supports let-values. (Having to 
>nest "let, then let-values, then let again" was another reason my code 
>would get too indented for my taste.)
> :

Possibly a stupid question, but ...

What causes you to /have to/  'nest "let, then let-values, then let
again"'?   Assuming no intervening body code, a single let*-values
could cover all of it (with the same semantics).

-- 
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/pjd1ngddbcqpak5ke8720uddit5h254vmk%404ax.com.


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

2021-10-13 Thread George Neuner



On 10/12/2021 7:01 PM, unlimitedscolobb wrote:

I wrote myself this little function:

(define (hash->ordered-list h)
  (hash-map h cons #t))

which uses the try-order? argument of hash-map.

Is there a reason for hash->list not have an optional argument 
try-order?  Or perhaps having such a standalone function would be better?


I was planning to submit a patch, but then I thought I may be missing 
something.


-
Sergiu



I can't speak for the Racket team, but ...

Hash tables entries inherently are unordered, so there really is no 
reason to expect an ordered list from reading out the data.  Also, the 
docs indicate that 'try-order?' doesn't work for all data types - so it 
may produce unexpected results.  Further, sorting the output potentially 
can take a lot of extra time ... having never tried to get ordered 
output from hash-map, I can only hypothesize that (at least in some 
cases) it may be faster to create the unordered list and then sort it 
than to try to produce an ordered list with 'try-order?'.


Certainly, you are welcome to submit a change, but I think it would be 
best to leave the existing behavior and make ordered output an addition.


YMMV,
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/a30ae67d-891e-82f5-f3be-cc1fc1f89263%40comcast.net.


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

2021-10-13 Thread George Neuner



On 10/12/2021 7:01 PM, unlimitedscolobb wrote:

I wrote myself this little function:

(define (hash->ordered-list h)
  (hash-map h cons #t))

which uses the try-order? argument of hash-map.

Is there a reason for hash->list not have an optional argument 
try-order?  Or perhaps having such a standalone function would be better?


I was planning to submit a patch, but then I thought I may be missing 
something.


-
Sergiu



I can't speak for the Racket team, but ...

Hash tables entries inherently are unordered, so there really is no 
reason to expect an ordered list from reading out the data.  Also, the 
docs indicate that 'try-order?' doesn't work for all data types - so it 
may produce unexpected results.  Further, sorting the output potentially 
can take a lot of extra time ... having never tried to get ordered 
output from hash-map, I can only hypothesize that (at least in some 
cases) it may be faster to create the unordered list and then sort it 
than to try to produce an ordered list with 'try-order?'.


Certainly, you are welcome to submit a change, but I think it would be 
best to leave the existing behavior and make ordered output an addition.


YMMV,
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/79f42508-fa28-f898-606d-f62bd3071eff%40comcast.net.


Re: [racket-users] racket/gui/base in sandboxes in places

2021-10-03 Thread George Neuner



On 10/3/2021 4:04 PM, 'William J. Bowman' via Racket Users wrote:

I'm trying to run sandboxes in places, but when the sandboxes need access to 
racket/gui (such as through 2htdp/universe), they get `cannot instantiate 
racket/gui/base' a second time`. I've tried initing racket/gui once in the 
server that starts the places, but this doesn't seem to work. (gui-available?) 
is still false in started places, and they still raise the exception when the 
sandbox tries to load the gui module.

I don't really need to run gui code in the sandbox, so I'm guessing the best 
workaround is to override `2htdp/universe` in the sandbox.

Anyone have either a solution, or a better workaround?


My (perhaps incorrect) understanding is that with dynamic (kernel 
thread) places, only the foreground place can have a GUI.  I'm not sure 
why the gui package won't load in a background place, but it may not 
work right even if you can get it to load.


Just a suggestion: you might try using Paulo Matos's "Loci" package - it 
simulates dynamic places using separate processes.  With Loci, the place 
is foreground in its own process, so it /might/ allow racket/gui to work.


https://pkgs.racket-lang.org/package/loci


Hope this doesn't lead down a rabbit hole.
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/8079cbe0-3f78-e0f3-024f-9b47459b8706%40comcast.net.


Re: [racket-users] Looking to trigger the end of a loop by the creation of a file.

2021-10-02 Thread George Neuner



On 10/2/2021 7:25 PM, Don Green wrote:

Looking to trigger the end of a loop by the creation of a file.
Is this possible? Is this advisable?
Currently using:
a 'for' loop with
a 'for' loop guard expression to test for the existence of a file.
Tried file-exists? but that does not seem appropriate.
Tried using Racket function: filesystem-change-evt but that did not 
seem appropriate.
Is it possible to trigger an end condition on a 'for' loop by the 
creation of a file?
I suspect my problem is that it takes a significant amount of time for 
the operating system to register the creation of a file.
So maybe the best that can be done is to use file-exists? as it works 
but there a many loops of the 'for' loop before the end condition 
takes effect.

Any comments? --


Is the loop doing something else while it waits?  If not, you might as 
well use  filesystem-change-evt.


A polling loop /may/ respond faster than waiting on an event, but at the 
level of user applications that is /not/ guaranteed.  Is there some 
reason you (think you) need to respond very quickly when the file is 
created?


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/4eef5249-c55b-6585-f04a-3cd947d26a27%40comcast.net.


Re: [racket-users] Re: jest...@gmail.com Trouble installing DrRacket

2021-09-13 Thread George Neuner


On 9/13/2021 10:34 PM, Matthew Flatt wrote:

Just to clarify: Racket runs on a number of ARM variants when running
Linux and other Unix-like operating systems, but we have not yet ported
to Windows on ARM.

Matthew


Is there a list somewhere of which chips have successfully run Racket?
Or a definitive statement of what ISA is targeted?

Just saying "if it runs Linux ..." isn't terribly helpful. /[I realize 
that you did not actually say that.]/   Linux can run in Thumb2, and the 
last time I checked there were at least 4 different ARM architectures 
for which Linux (or some reasonable subset) had been made to run on some 
representative chip.


Doesn't mean Racket will run on it.  It's really applications that 
stress chips, not operating systems.


YMMV,
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/09ddf2e2-e6bc-045f-8444-f291c92a62a9%40comcast.net.


Re: [racket-users] Re: jest...@gmail.com Trouble installing DrRacket

2021-09-13 Thread George Neuner


On 9/13/2021 1:02 PM, Nathan Philippon wrote:

It's a Samsung GalaxyBook

On Monday, September 13, 2021 at 12:48:06 p.m. UTC-4 jest...@gmail.com 
wrote:


Yeah, I don't think Racket supports windows on arm devices. I'm
guessing this is a chromebook or something? HP? Dell?
On Monday, September 13, 2021 at 8:44:08 AM UTC-7
hockeyfa...@gmail.com wrote:

I tried replying in the same thread but my messages kept
getting deleted.
Processor: Snapdragon (TM) 7c Gen 2 @ 2.55 GHz   2.55 GHz
RAM: 4.00GB



Disclaimer:  I am not part of the Racket development team.

I don't think Racket is supported on a Chromebook.  Even so, there are a 
number of issues with running Racket on ARM ... there simply are too 
many variations of ARM chips to test the code on all of them.  Some just 
can't run the current codebases (BC or CS), and I am pretty sure BC's 
JIT compiler is not supported on any of them.


It may be that Racket (currently) just won't work on your chip.  Or it 
may be something with ChromeOS.



Sorry.  I know this wasn't particularly helpful.
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/a4de3df3-37e0-2292-310f-8cdff35d2f4a%40comcast.net.


Re: [racket-users] Is there an easy way to disable a GUI element?

2021-09-03 Thread George Neuner



On 9/2/2021 5:39 PM, Ryan Kramer wrote:
I see that button% has an `enabled` field, but I'm not seeing anything 
for slider%, text-field%, and choice%. If I want to disable these 
elements, do I have to roll my own enable/disable logic? Also, is 
there a way to change a button's `enabled` status after it is created? 
Thanks.


All the controls respond to window<%> messages: e.g., (send /mybutton/ 
enable #t)

    https://docs.racket-lang.org/gui/window___.html

Whenever possible, you should try to use object messaging / method calls 
rather than directly messing with fields in the objects (even if the 
fields are public).

    https://docs.racket-lang.org/reference/ivaraccess.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/86b63058-bbd4-f0d0-e9d3-af625c3b85c9%40comcast.net.


Re: [racket-users] problem of gui layout using side-by-side frames

2021-08-12 Thread George Neuner


On 8/12/2021 2:52 PM, Jens Axel Søgaard wrote:
Den tor. 12. aug. 2021 kl. 20.44 skrev George Neuner 
mailto:gneun...@comcast.net>>:



If I understand correctly, Don seems to want menus in his
side-by-side
"panels".


Are we talking menu bar menus or contextual menus?

On macOS the menu bar menu belongs to the application and not a window.

https://developer.apple.com/design/human-interface-guidelines/macos/menus/menu-anatomy/ 
<https://developer.apple.com/design/human-interface-guidelines/macos/menus/menu-anatomy/>


/Jens Axel


Don will have to answer that definitively.

But quoting from one of his previous posts:

   "When I specify 2 frames to be side-by-side using racket/gui, I
   believe I would have no problem if all my prospective client
   platform did not have a vertical Operating System taskbars. Since I
   do have such a taskbar I must use code that takes the width of the
   taskbar into account."

   "I am currently of the belief that I should refrain from using
   side-by-side frames.  The upshot is that I can then no longer use
   menus either because menus can only exist in frames and I would need
   more than the single top-level frame."

That tells me zip about what platform he is targeting, because MacOS, 
Windows, and several of the Linux display managers all support some 
notion of a vertical taskbar.


However it does suggest that he wants menubar menus.  I don't use (or 
have available to check) MacOS, so I'm don't know what limitations may 
be on 'root menubars, or whether a child frame can have its own internal 
menubar (which is possible on Windows and Linux).


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/edefed61-4303-b56c-3d58-109789f69565%40comcast.net.


Re: [racket-users] problem of gui layout using side-by-side frames

2021-08-12 Thread George Neuner

On 8/12/2021 1:39 PM, kamist...@gmail.com wrote:
I think instead of fidgeting around with OS dependent stuff to align 
frames side by side,

I would take another approach (inspired by other applications):

1. per default the application is just a big window with multiple 
sections divided with panels, splits, tabs, etc.
2. some of those areas might be useful as sepparate frames for some 
users, add a button "undock"
3. clicking that button creates a frame and reparents the panel into 
the newly created frame

4. button changes to "dock"
5. clicking it reparents the panel back to where it was originally and 
deletes the frame


There might be some coding needed to save and restore state about what 
has been undocked and the last positions of the windows,

so that can be restored when the application is restarted.
(although some OS's may restore window positions themselves if they 
have unique titles??)


What I like about that approach is that it gives the user choice and 
can be ignored if its not needed.



If I understand correctly, Don seems to want menus in his side-by-side 
"panels".


Currently a menubar must be a child of a frame - so, to have menus, 
Don's "panels" must be frames.  But that is ok, because a frame can be a 
child of another frame.


Allowing (un)docking is a good idea (if applicable), but switching 
between panels and frames is unnecessarily complicated ... a frame can 
be drawn floating or docked, resizeable or not, with or without borders, 
system menu, captions, toolbar, menubar, etc. - so visually it can be 
made to /appear/ as if a panel when docked, and as if a window when 
undocked.  It's a lot easier to just redraw the frame(s) with different 
settings than to try to maintain multiple different object hierarchies 
or to try to reassign parentage on the fly (which is mistake prone if 
many functions are handled by the parent).


YMMV,
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/2eb0a4bd-c71b-107b-dce8-ff33f26d7baf%40comcast.net.


Re: [racket-users] problem of gui layout using side-by-side frames

2021-08-12 Thread George Neuner



On 8/11/2021 10:44 PM, Don Green wrote:


When I specify 2 frames to be side-by-side using racket/gui, I believe 
I would have no problem if all my prospective client platform did not 
have a vertical Operating System taskbars.
Since I do have such a taskbar I must use code that takes the width of 
the taskbar into account.

Since I intend to distribute to others who may have:
a) no vertical taskbar; or
b) a wider vertical taskbar; or
c) multiple vertical taskbars
no single offset can be used and it is outside the scope of the 
racket/gui to know what the offset would need to be.
I am currently of the belief that I should refrain from using 
side-by-side frames.
The upshot is that I can then no longer use menus either because menus 
can only exist in frames and I would need more that the single 
top-level frame.

Any suggestions?
I am currently thinking I should use the panel-tab with a couple of 
panels each containing an editor-canvas and place buttons on these 
panels instead of using menus. --


I don't quite understand the problem - a frame can have another frame as 
its parent (supporting Windows "multiple document interface").  If you 
need side-by-side frames with menus, then why not do that inside an 
enclosing top-level frame?


Also pop-up menus have no parent and can be used anywhere.

And if you really are ambitious, you could make the menubar% class work 
within panels as well as frames.  This has been mentioned occasionally 
over the years, but AFAIK nobody ever has bothered to look into it.


--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/5c29e25d-aa1d-1326-2d3e-ca6b3cbe9175%40comcast.net.


Re: [racket-users] frame width and (get-display-size) ...

2021-08-06 Thread George Neuner


I have no idea what this code will do on MacOS, but it works on Windows 
... at least for the limited window tilings I tried.


YMMV.

-
#lang racket
(require racket/gui)
(define-values (w h) (get-display-size #:monitor 0))
(printf "screen: ~a ~a~n" w h)

(set! w (/ w 2))
(set! h 100)

(define f1 (new frame% [label "Window 1"] [height h] [width w] [y 0] [x 0]))
(define f2 (new frame% [label "Window 2"] [height h] [width w] [y h] [x w]))
(define f3 (new frame% [label "Window 3"] [height h] [width w] [y (+ h 
h)] [x 0]))


(define (align frm)
  (let*-values [
    ((wx)    (send frm get-x))
    ((wy)    (send frm get-y))
    ((ww wh) (send frm get-client-size))

    ((dx dy) (send frm client->screen 0 0))

    ]
    (printf "~s:~n" frm)
    (printf "~a,~a ~a ~a~n" wx wy ww wh)
    (printf "~a,~a~n" dx dy)
    (printf "~n")

    (let ((dx (- wx dx)))
  (send frm move (+ wx dx) wy))
    (send frm resize
  (+ w (abs (- ww w)))
  (+ h (- h (+ wh (- dy wy
  )

    (send frm show #t)
    ))

(align f1)
(align f2)
(align f3)
-


--
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/e5b86730-d78c-d445-2fa2-b2b78b632f77%40comcast.net.


Re: [racket-users] Equivalent of exec

2021-08-03 Thread George Neuner



On 8/3/2021 1:03 PM, Norman Gray wrote:

On 3 Aug 2021, at 17:38, George Neuner wrote:

Racket is multi-platform and tries to present a common API for 
dealing with underlying operating systems.  Windows is an important 
platform, but Windows does not have the concept of fork/exec ... so 
Racket doesn't offer it either.


Ah: good point.  That said, I'd have guessed that similar behaviour -- 
'invoke and don't return' -- would be at least emulatable on Windows, 
though.


Well, yes, but the behavior of  'CreateProcess'  is quite different from 
the combination of  'forkv/execv'.


In Windows, the new child is not (even virtually) a copy of its parent - 
it is a completely new process context.  Although it is possible for the 
parent to pass to and/or share resources with the child, this doesn't 
include a copy of its memory context [so no 'fork'].  The parent 
receives several handles to the new child process that must explicitly 
be closed in order to detach it.


As a technical matter, emulating Unix 'fork' in Windows ... i.e. making 
an independent copy of the parent process that continues running from 
where the parent stopped ... is possible, but it is difficult and 
requires debugger like behavior to manipulate the child's memory map and 
copy data from one process to the other.



The closest (and simplest) you can achieve, I think, would to start 
Vi asynchronously using 'process*' and then terminate the Racket script.


I don't think that works, since terminating the Racket process would 
also terminate its child (unless I were to do something similar to the 
usual extra fork to disconnect the child from its parent, and... hmmm, 
this isn't sounding very rackety).


Doing the next simplest thing -- using (process* "/usr/bin/vi" 
'("foo")) and calling (control 'wait) using the result -- doesn't seem 
to work, but instead just hangs, until I kill the vi child process.  
Without digging into it too deeply, I'd guess that's because of the 
usual problems about wiring up FDs and buffers and so on, which I was 
rather hoping to avoid.




Hmm.  According to the docs  'process'  (no asterisk) executes the 
command asynchronously ... I assumed  'process*' would do the same. 
Unfortunately 'process' returns ports that must be closed explicitly.


Sorry if I led you astray.



Best wishes,

Norman


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/720fc753-7972-b8c1-76ec-4d2a65a763f2%40comcast.net.


Re: [racket-users] Equivalent of exec

2021-08-03 Thread George Neuner

On 8/3/2021 12:14 PM, Norman Gray wrote:


Greetings.

I can't find a way of doing something equivalent to exec in Racket.  
Is this Hard, or am I just missing it?


By 'exec', I mean the equivalent of replacing the process with a new 
image, as distinct from `system` (and friends) or `process` (and 
friends), which are concerned with creating a subprocess, controlling 
it, and handling its exit.


In my particular case, I want to call vi at the end of a Racket 
script.  I'm sure it's possible to do that with process and friends, 
but it would require being careful about input and output ports, 
worrying about buffering, whether things are terminals or not, and so 
on and on.


I can imagine this isn't trivial as an implementation issue -- I can 
see there would potentially be custodians to worry about (*waves hands 
vaguely*), but I'd be surprised if it were impossible.  However I'm 
completely failing to find anything on [1], searching for eg 'exec' or 
'return' (as in 'does not return'); and 'exec' isn't a very handy 
search term on the web.


Thanks for any pointers,

Norman

[1] https://docs.racket-lang.org/reference/subprocess.html



Hi Norman,

Racket is multi-platform and tries to present a common API for dealing 
with underlying operating systems.  Windows is an important platform, 
but Windows does not have the concept of fork/exec ... so Racket doesn't 
offer it either.  The closest (and simplest) you can achieve, I think, 
would to start Vi asynchronously using 'process*' and then terminate the 
Racket script.


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/2ab522f1-ea58-3a34-3ed5-24998a64da0f%40comcast.net.


Re: [racket-users] Can I get the behavior of `overment` followed by `augride` with a single class?

2021-07-17 Thread George Neuner



On 7/17/2021 1:10 AM, Alexis King wrote:
   :
  a complex, possibly error-prone, way to front-end class method dispatch
   :

This brings me to my question: is there any simpler way to do this? 
And are there any hidden gotchas to my technique?


I'm still trying to understand how it works.  8-)


However, it occurs to me that, in Lisp, using defgeneric with 
/method-combination :most-specific-last/  solves the problem quite 
nicely.  Eli Barzilay's old Swindle package still is available ... I 
know it had generic methods, but I don't recall whether it implemented 
method combination.


I also recall some years back that you wrote about using racket/generic  
and created a simple multiple dispatch system. There doesn't seem to 
whole be a lot of documentation regarding generics (other than as 
applied to interfaces), so I'm fuzzy on what they can / can't do.



Anyway I doubt Lisp-like generic methods are what you want (else you 
wouldn't have started with classes), but it seems that you are trying to 
achieve similar functionality.


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/6347d4ce-7652-a44e-9a15-5e2d796797f3%40comcast.net.


Re: [racket-users] Question from a beginner. Why Racket Over Scheme?

2021-07-13 Thread George Neuner


On 7/13/2021 10:13 AM, joseph turco wrote:

Hello,

Im am looking at learning a programming language, and have been 
bouncing around with scheme/racket/dyalog APL/squeak. upon 
investigation of scheme and racket, i found that in regards to racket, 
there really isn't a "Beginners book" that teaches the language. The 
only beginner book i could really see being close to teaching the 
language is HtDP, but that doesn't /technically/ teach racket, but 
BSL. For scheme, im able to find beginner books, unless im not looking 
deep enough. Maybe if you fine folk don't mind pointing me in the 
right direction? Please excuse my ignorance.


-- Joseph T


Welcome.

Racket[*] largely is based on Scheme, and so much of what you learn 
about Scheme will transfer.  Racket supports R5RS and R6RS Scheme as 
legacy languages, so you can learn about Scheme /using/ Racket and its 
tools.  Then when you are more comfortable, you can transition to using 
the Racket module language instead.


George
[*]  At least the untyped Racket language.  Racket really is a /suite/ 
of languages: there also is a typed Racket, a lazy Racket, and various 
DSLs (domain languages) which compile to and (mostly) freely intermix 
with 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/a5940fd5-a3b1-152e-7efc-66c98a2ad941%40comcast.net.


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

2021-07-01 Thread George Neuner



On 7/1/2021 2:36 PM, David Storrs wrote:

What is the best way to pass a function into a child `place`?


1.  just define the functions in a context the place can see
2.  send the name of a local file for the recipient to dynamic-require
3.  send the definition file for the recipient to save locally and 
dynamic-require

4.  define the function(s) with serial-lambda and serialize / deserialize


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]


Not a problem if using /dynamic/  (thread in same process) places.
See
   https://docs.racket-lang.org/reference/places.html
https://docs.racket-lang.org/reference/places.html?q=place#%28part._places-syntax%29

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.


You /can/ do that ... but you don't ever have to stoop to eval.

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?


Depends on whether you're using /dynamic/ (same process) or 
/distributed/ (separate process) places.


With dynamic places you can (often) just provide the code for the place 
to execute.  For complicated things you may have to use 
serial-lambda/serialize/deserialize, but often you can simply provide 
the necessary functions in context.




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


And invalidating any part of the visible window does the same thing 
until the window is redrawn.



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/cc734b4f-f59e-7536-b336-5225ba93752d%40comcast.net.


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

2021-06-18 Thread George Neuner

Hi Matthew,

Sorry for the delay in replying.


On 6/17/2021 7:08 PM, Matthew Flatt wrote:

At Wed, 16 Jun 2021 17:33:56 -0400, George Neuner wrote:
> 
> Dumb question ... why should non-blocking I/O worry about "flush" at 
> all.  Why not behave like native I/O where writes are guaranteed only to 
> get to the I/O buffer?


If I understand what you mean, then that's the intent. But I think
you're using "buffer" in the sense of the OS layer. That's different
than the buffer that you have in, say, the C library. The Racket port
model uses "buffer" to mean the one like the one implemented in a C
library, and "flush" is used also used in the C library sense, and not
in terms of a buffer that might exist in the next layer (which might be
the OS or might not).


I was not necessarily thinking about any particular layer, but I was 
thinking about open files, TCP connections, etc.  I know that both [or 
neither] the OS and the I/O library may implement buffering.


My point was that the docs for write-bytes-avail et al specifically 
mention "flush" of data, and in a way that implies (to me) that there is 
expected to be something else underlying the buffer to "flush" to, e.g., 
storage media, network connection, etc., ... something.  But, if I 
understand correctly, Racket pipes are a library construct and really 
just a named block of memory.


So it seems like "flush" is being used in the docs to mean insertion of 
data into the buffer ... which is confusing (to me) and at odds with how 
the word typically is used in discussions of I/O.  To reveal prejudices, 
I've been programming for 40 years and Racket is an umpteenth language.




Probably this became more clear with experiments that Shu-Hung and you
reported, but that's what happens, except that trying to write to a
pipe whose buffer is full will then grow the buffer. Naturally, the
buffer grows by doubling --- up to the pipe's capacity limit, if any.

An OS pipe tends to have a fixed size (OS-level) buffer that is
allocated up front, and that serves as both the maximum granularity of
writes and the capacity of the pipe. Racket pipes are meant to work in
those kinds of cases, but also adapt to cases where pipes are small and
numerous or where they have no capacity limit, so the write granularity
and capacity are not so tightly coupled.


So the limit value passed to  make-pipe  is only a maximum size for the 
data buffer, which starts [way too] small and then grows as needed up to 
the maximum.  Although that does make some sense - I think starting at 
16 bytes is a wee bit restrictive: many (most?) real world uses would 
have to grow it very quickly.


I think many (most?) of us expected that Racket pipes would behave like 
OS pipes - a fixed length allocation up front - and that a single call 
to  write-bytes-avail  would fill the buffer.  [It turns out that it 
/does/ fill the buffer, but the buffer isn't what we thought it would be.]




There's likely room for improvement. Racket BC pipes absorb more in a
non-blocking write, because MzScheme was very slow in the old days, and
it was worth looping and trying harder in the low layers instead of
having to go back out to slow MzScheme code. For Racket CS, that
slow--fast boundary isn't there, and so the lower layer core tries to
stay as fast as possible by branching and looping less internally, but
I don't really know if that's the best choice.


Growing the buffer is expensive in any case and particularly when 
existing data has to be copied.  With pre-allocated buffer, the I/O call 
will spend only what time is necessary to copy new data.  That would 
seem to be the fastest implementation possible.



Anyway, thank you very much for explaining it.
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/71be924c-e88e-fd91-ea94-af6694c90a0e%40comcast.net.


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

2021-06-16 Thread George Neuner



Forgot to mention this is using  CS 8.1

--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/70ba930a-e7fe-af8a-3b57-0800d15c945c%40comcast.net.


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

2021-06-16 Thread George Neuner

On 6/16/2021 7:01 PM, Shu-Hung You wrote:

Out of curiosity, I wrapped David's code in a loop and tried to write
509 bytes in each iteration. From the output, it looks like CS doesn't
implement pipes using a fixed-size buffer. I'm also not sure how many
different buffers there are. I think this has something to do with
George's question.
 :


Continuing in this vein, it seems that the count of bytes written starts 
small and then doubles with each successive write until finished (or 
until the buffer fills).   I'm guessing this has to do with thread 
scheduling applied to I/O ... ie. try a short write (minimum quantum), 
and if it isn't finished try a longer write (longer quantum) ???




(define msg-size 15700)
(define bstr (make-bytes msg-size 42))

(define rx-pipe-size 16384)
(define-values (rx-in rx-out) (make-pipe rx-pipe-size))

(define (available?)
  (- rx-pipe-size (pipe-content-length rx-out)))

(let loop ((start 0) (full? #f))
  (cond
    [full? (displayln "buffer full")]
    [(>= start msg-size) (displayln "done")]
    [else
 (let ((written (write-bytes-avail* bstr rx-out start)))
   (printf "written: ~a  starting at  ~a~n" written start)
   ;   (printf "available: ~a~n" (available?))
   (loop (+ start written) (= written 0))
   )
 ]))


written: 15  starting at  0
written: 16  starting at  15
written: 32  starting at  31
written: 64  starting at  63
written: 128  starting at  127
written: 256  starting at  255
written: 512  starting at  511
written: 1024  starting at  1023
written: 2048  starting at  2047
written: 4096  starting at  4095
written: 7509  starting at  8191
done


With the "msg" size changed to exceed the buffer:

written: 15  starting at  0
written: 16  starting at  15
written: 32  starting at  31
written: 64  starting at  63
written: 128  starting at  127
written: 256  starting at  255
written: 512  starting at  511
written: 1024  starting at  1023
written: 2048  starting at  2047
written: 4096  starting at  4095
written: 8192  starting at  8191
written: 1  starting at  16383
written: 0  starting at  16384
buffer full





--
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/6b252cfe-ca16-073b-5164-1bb784095825%40comcast.net.


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

2021-06-16 Thread George Neuner



On 6/16/2021 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.


Dumb question ... why should non-blocking I/O worry about "flush" at 
all.  Why not behave like native I/O where writes are guaranteed only to 
get to the I/O buffer?




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.


It is not a problem, per se, but it is an issue that with a long string, 
you may be forced to call  write-bytes-avail  multiple times just to be 
filling up the port buffer.  That seems very inefficient and is at odds 
with how native non-blocking I/O calls behave (completing or filling the 
buffer before returning).


YMMV,
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/5257581b-e863-2a2c-e3a3-802b79016281%40comcast.net.


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

2021-06-16 Thread George Neuner


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

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


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

2021-06-16 Thread George Neuner


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.


[racket-users] Re: Embedded Racket reimplementation for constrained hardware?

2021-06-08 Thread George Neuner
On Sun, 6 Jun 2021 07:26:09 -0700 (PDT),
"schle...@gmail.com"
 wrote:

>I think in such an environment I would like to control memory usage myself, 
>or maybe have a #lang that allows very fine grained and low level control 
>over resources. (outputting lowerlevel code than racket/base). 
>If you need persistent data-structures they are nice, but often times you 
>don't need them. 
>Basically I would use a smaller language and build only the things I really 
>need, instead of starting with racket and stripping away everything I don't 
>need. 
>(although if you manage to create a tool that accomplishes this in a very 
>radical manner that could be cool as well, I just don't think that is easy)

I doubt Racket can be used directly as it was not designed to work
with programmer managed memory, but it could be used as a cross
development environment.  For reference there is Scheme48 which was
designed for embedded use.  Scheme48 compiles to C and does /not/ use
GC but rather forces the programmer to manage memory explicitly.
However, there's no particular need to go through C if you're willing
to write your own compiler and runtime.

>That would boil down to partially evaluating racket specializing it to the 
>target program, I don't think tools like `raco exe`, `raco distribute` etc. 
>go so far that they would try to eliminate
>base language features, which probably aren't "unused" anyway in any 
>reasonably complex program.

Yeah, I think some significant work would have to be done to separate
'base' into smaller libraries ... if that even can be done at all.


>Said another way: I think in a lot of cases it is easier to start creating 
>a program with a language with less features, than trying to get rid of 
>certain features after the program was already written using these 
>features. If you start out without the features it is easier to reason 
>about what features are worth implementing, for the particular program and 
>what is over-engineered for the use-case.
>That is just my perspective, I think there are many approaches to this, 
>depending on the circumstances and concrete goals.
>
>Simon

As a technical matter, GC works fine in small memory as long as it is
designed for that purpose.  The problem is that the GCs employed by
(BC and CS versions of) Racket were /not/ designed for particularly
small systems.

But the design space of GC is large, and collectors have been designed
to work in almost every environment except HRT with sub-millisecond
deadlines.  There are systems that are completely deterministic and
which can be used for HRT as long as the periods when the mutator must
be stopped are short enough for the purpose.

YMMV,
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/mmhubg92kiggthhlrfp483sfu0hga86r79%404ax.com.


[racket-users] Re: Embedded Racket reimplementation for constrained hardware?

2021-06-05 Thread George Neuner
On Sat, 5 Jun 2021 06:45:44 -0700 (PDT), dbohdan
 wrote:

>Has anyone tried making a small embedded implementation of Racket?  I mean 
>"embedded" not in the sense of 8-bit microcontrollers but more powerful yet 
>still constrained devices, like routers with 64 MB RAM running Linux or the 
>PlayStation 2.  I think you don't have to work from scratch to make one.  
>You can implement Racket on top of an embedded Scheme like Chibi-Scheme 
>.  It doesn't need to be a full, 
>maximally compatible port of Racket like Racket CS, just a large subset.  
>For example, you can skip  futures and places.
>
>What features do you need to implement natively in the interpreter rather 
>than in Scheme?  You can implement delimited continuations in terms of 
>call/cc.  The concurrency primitives (threads, boxes, etc.) and the FFI?  
>You may be able to, but don't have to, optimize the interpreter for 
>immutable conses.
>
>This is just something I have been musing about.  If no project like this 
>exists, I am not starting one soon.

Racket can run in less than 64MB, but severely limited memory
typically results in a lot of GC churn.

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/3pbnbgtsk18g1dpg8951h9nvjuu448gmja%404ax.com.


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

2021-05-19 Thread George Neuner

Coming late to this ...

On 5/19/2021 11:31 AM, David Storrs wrote:
On Tue, May 18, 2021 at 4:09 PM Philip McGrath 
mailto:phi...@philipmcgrath.com>> wrote:


On Tue, May 18, 2021 at 3:52 PM Sam Tobin-Hochstadt
mailto:sa...@cs.indiana.edu>> 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?


The connect will occur once before the dynamic-wind is entered. However, 
because it is outside dynamic-wind rather than in the pre thunk - 
connect will /not/ be executed again if the value thunk is reentered.


call-with-continuation-barrier, in effect, puts a sandbox around the 
contained thunk which prevents continuations captured within the thunk 
from being invoked outside of it.  IOW, you can jump around /inside/ the 
thunk, and you can jump out of the thunk ... but if you jump out, you 
/can't/ jump back in.


As used in the example, the barrier around the value thunk turns 
dynamic-wind into the moral equivalent of Lisp's unwind-protect: modulo 
exceptions, pre and value will be executed at most once, and post is 
guaranteed to be executed regardless of whether pre or value finish.


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/ccf271c7-420e-ded7-ec39-c29bb4f2663d%40comcast.net.


Re: [racket-users] copy-file does not preserve file attributes on linux version of Racket...

2021-05-10 Thread George Neuner



On 5/10/2021 8:16 PM, Don Green wrote:
From Racket doc: "File permissions are transferred from src to dest; 
on Windows, the modification time of src is also transferred to dest."


Is the above line meant to imply that a unix/linux version of Racket 
will NOT preserve file attributes using copy-file?


I don't know the answer to your question re: Racket's copy-file, but I 
would point out that in the OS the create, modify, and access times for 
files all are maintained separately.  A program (with sufficient rights) 
can change them independently.


--
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/6ae995ed-58fc-38cf-608e-0e5ba7616bc6%40comcast.net.


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

2021-04-07 Thread George Neuner



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/5559332c-4849-795c-94b5-884dfb29d75f%40comcast.net.


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

2021-02-24 Thread George Neuner


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 everyone need to know?" "me" 
"participant"))]


    [(regexp-match #px".*,+\\s*world!" str)
 (say chat-history (message "Did the whole world really need to 
hear that?" "me" "participant"))]


    [else (say chat-history (message "Did you really just say 
something without addressing the \

world? I am so proud of you! :,)" "me" "participant"))])

  (define hd (head chat-history))
  (define s (message-str hd))
  (printf "Chatbot: ~a\n" s)
  (loop)) --
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/ae6488a3-3b70-4de7-8a1f-8f5526e63580n%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/1323324c-372f-ff37-efdb-d888d2c223dc%40comcast.net.


Re: [racket-users] Unsafe structs

2021-01-21 Thread George Neuner


On 1/20/2021 1:53 AM, Sorawee Porncharoenwase wrote:


However, ‘struct-field-info-list’ returns only fields defined by the
actual type and does not include fields that were inherited. What I
don’t see is any simple way to get at the struct’s inheritance
hierarchy
—- it seems that you have to iterate ‘struct-type-info’ to
enumerate the
supertypes.

Yes, that’s a (the?) way to extract field names of supertypes. The 
reason I designed it in that way is that field name is a concept for 
each level in the hierarchy, not across levels. You can’t have two 
identical field names in a level, but you can have identical field 
names across levels. So lumping field names across levels together 
doesn’t look like a good idea to me.




Yes, but fields defined in an ancestor are visible in its descendants.  
I understand the need to distinguish the individual types, but  
'struct-type-info'  does that already.  IMO there should be an easy way 
to get information on *all* the fields at once - potentially including 
which supertype(s) defined them.


YMMV,
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/ba71e843-a3ae-d2ad-646d-27951b700485%40comcast.net.


Re: [racket-users] GUI button% string label keyboard mnemonics

2021-01-09 Thread George Neuner



On 1/9/2021 3:20 AM, Dominik Pantůček wrote:

> Maybe a stupid question ...
> 
> Is  "close-icon" the name of the bitmap or a function that creates a

> bitmap?

I am using images/icons/misc:

https://docs.racket-lang.org/images/Icons.html?q=close-icon#%28def._%28%28lib._images%2Ficons%2Fmisc..rkt%29._close-icon%29%29

So it generates a bitmap% in the end.

> Have you tried:
> 
>    (new button% (label close-icon "" 'left) ...)
> 


Just out of curiosity right now and no, the button% does not accept
procedure to be a part of that list.


Unfortunately, I'm not well versed in Racket's GUI library - I have done 
a lot of GUI work in C and C++.


In the OS graphics [X, GDI, etc], the button and the icon are separate 
objects: e.g., deleting the button will not also delete an icon attached 
to it, so if the icon doesn't have its own handle, you'll lose it and 
have a resource leak.


These things often are handled at higher level by the graphics libraries 
- and Racket may do that [I don't know] - but my first thought would be 
to name the icon separately, and then pass the name to the button 
constructor.  E.g.,


    (define my-icon (close-icon))
(new button% (label my-icon "" 'left) ...)


I'm thinking that the button isn't functioning correctly because it 
isn't being constructed improperly.  Theoretically the reference to the 
icon should be the same regardless, but a lot of the library is macro 
code and who knows what it really expects.  When in doubt I try to simplify.


YMMV,
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/2e87e4e8-a576-46e2-0c62-536dac872cab%40comcast.net.


Re: [racket-users] GUI button% string label keyboard mnemonics

2021-01-08 Thread George Neuner



On 1/6/2021 2:56 PM, Dominik Pantůček wrote:

When a button is created like:

(new button% (label "") ...)

everything works as expected. The #\q key becomes a keyboard shortcut
that triggers the callback correctly.

But when the string label is given in the list of icon and label like:

(new button% (label (close-icon) "" 'left) ...)

The "&" is left intact and no action is triggered by pressing the #\q
character on the keyboard.

The documentation clearly states both alternatives as supported: "If &
occurs in label (when label includes a string), it is specially parsed;
...". Am I doing something wrong or is it a bug?


Maybe a stupid question ...

Is  "close-icon" the name of the bitmap or a function that creates a bitmap?
Have you tried:

   (new button% (label close-icon "" 'left) ...)


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/9ddad8d8-6904-874e-7ff5-cee32ad23ebe%40comcast.net.


Re: [racket-users] Unsafe structs

2020-12-21 Thread George Neuner



On 12/20/2020 3:34 PM, Dominik Pantůček 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.


Have you looked at 'struct-field-info-list' and 'struct-field-index'?

'struct-field-index' works if you know the field name(s), and 
'struct-field-info-list' returns fields defined by the struct type - so 
if your structs types are flat, you can make do with these.


However, 'struct-field-info-list' returns only fields defined by the 
actual type and does not include fields that were inherited.  What I 
don't see is any simple way to get at the struct's inheritance hierarchy 
- it seems that you have to iterate 'struct-type-info' to enumerate the 
supertypes.


So it is "possible" (for some definition).
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/303f6b17-61e2-587c-9636-caca3444ddd4%40comcast.net.


[racket-users] Re: I want to find the width of this image, why it says unbound identifier?

2020-12-05 Thread George Neuner
On Sat, 5 Dec 2020 19:26:30 -0800 (PST), Yi Chen
 wrote:

> #lang slideshow
> (define cat )
> (image-width (cat))

There is no function "image-width" in slideshow.  

see: https://docs.racket-lang.org/search/index.html?q=image-width
To use "image-width" you must require one of these library modules:
 - htdp/image
 - 2htdp/image
 - quadwriter


Additionally your syntax is wrong: it should be "(image-width cat)".
With the parentheses, "(cat)" is a call of a function named "cat" -
however "cat" is not a function but simply an image.

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/va2psf5vv4ilbd52ihgrmo8dojoosuglkf%404ax.com.


Re: [racket-users] named let ...

2020-11-26 Thread George Neuner


On 11/26/2020 11:22 PM, Tim Meehan wrote:
I was trying to turn one of Knuth's random number sampling without 
replacement algorithms. It seems to be working, but when it comes time 
to return my prize ... nothing :(


I thought that since I was returning from inside of the named let, 
that I'd get back my collection of numbers sampled without replacement.


;; algorithm taken from:
;; 
https://stackoverflow.com/questions/311703/algorithm-for-sampling-without-replacement 


(define (sample-without-replacement n N)
  (let loop ([num-seen 0]
   [num-stored 0]
   [result '()])
    (let ([u (random)])
(display (format "~a\n" result))
(unless (>= num-stored n)
(if (>= (* u (- N num-seen)) (- n num-stored))
  (loop (add1 num-seen) num-stored result)
  (loop (add1 num-seen) (add1 num-stored) (cons num-seen result
result)))


How to explain this ...

The problem is that 'unless' does not end the function - the calls to 
'loop' are *not* in tail position, so although you are recursing, you 
are not tail-recursing.  Your code doesn't exit at the bottom but rather 
unwinds the call stack, returning from 'loop' and and evaluating 
'result' every time.  At the top level, 'result' is the empty list 
(passed as the argument) and that is what is being returned.


Contrast with:
  (if (>= num-stored n)
    result
    (if (>= (* u (- N num-seen)) (- n num-stored))
    (loop (add1 num-seen) num-stored result)
    (loop (add1 num-seen) (add1 num-stored) (cons num-seen 
result


When you have this kind of multiple test logic, 'cond' is your friend:
  (cond
    ((>= num-stored n)
 result)
    ((>= (* u (- N num-seen)) (- n num-stored))
 (loop (add1 num-seen) num-stored result))
    (else
 (loop (add1 num-seen) (add1 num-stored) (cons num-seen result

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/4e21e51e-0d8e-8b76-8422-7b88d3972415%40comcast.net.


Re: [racket-users] executables

2020-11-24 Thread George Neuner


On 11/24/2020 7:34 PM, Tim Meehan wrote:
Some Schemes allow you to compile to a (self-hosting?) executable 
(Chicken {via C}, Chez, Racket, others?). Some do not (Guile, 
others?), but compile to bytecode.


Why would a group of developers choose one over the other? Or is the 
end result not that different in either case?


The reason for creating stand-alone executables is to be able to run 
programs in environments where the language tools are not, or cannot be, 
installed.  For security reasons, many companies do not permit 
installing programming tools.


However, creating stand-alone executables is rather unrelated to what 
the compiler produces.  There are a number of language implementations - 
Racket included - which can embed their bytecode (as static data) into a 
native "runtime" program which executes it.



Is there a book/paper that I might read on this?


Unfortunately, language implementation is a very large subject area.  If 
you want to understand why things are being done a certain way, you need 
to understand the ways that they *could be* done and what trade-offs are 
involved in using various methods.


Little understood fact:  all languages actually are defined by a 
*virtual* abstract machine.  This is the reason that languages can be 
implemented on many different real-world CPUs:  it is the abstract 
machine that defines the language's behavior, and it is the abstract 
machine - not some CPU - that is the *real* compilation target.
[For those about to object: yes, Scheme has a formal denotational 
definition in contrast to the many languages that are operationally 
defined by (relatively) informal description of behavior combined with a 
"reference" implementation.  Consider that Scheme's denotational spec is 
describing the behavior of an abstract machine, and that Scheme 
implementations are realizations of the machine.]


To get a sense of what is going on under the hood, you need to learn a 
bit about hardware, and a lot about compilers and interpreters. 
Particular language features often can be implemented in multiple ways, 
and the choices made for various features often affect how harmoniously 
they can coexist.


If you really are serious about learning this stuff, I'm sure we can 
keep you busy reading for a while.



Cheers,
Tim


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/8a2d8868-41b7-7b3c-eba2-2cf0517032a8%40comcast.net.


Re: [racket-users] read-line-evt question

2020-11-18 Thread George Neuner



On 11/18/2020 9:43 AM, Javier Vivanco wrote:


I have a question about a read-line-evt 's behaviour.
Is this normal this ?
> (sync (read-line-evt (current-input-port))
1234
""

I want to use a timeout in read-line via sync/timeout

but it always gives me the first character



You are seeing the return value from 'sync' rather than the event data.

Contrast with:

  (let [ (e (read-line-evt (current-input-port) )) ]
    (sync e)
    e )

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/ea1998da-1d7e-4d94-b1d8-2572cb37be11%40comcast.net.


Re: [racket-users] Regarding collections and racket versions...

2020-11-02 Thread George Neuner



On 11/2/2020 1:08 PM, infodeveloperdon wrote:
All of my programming code is in a single collection: 
~/.plt-scheme/4.2.1/collects/

even when I have installed newer versions of Racket.
   :
I appreciate any comments or advice regarding collections in general, 
or my use of the single collection directory: 
~/.plt-scheme/4.2.1/collects/


You should not be doing active development in the collection directories 
... they are meant for *stable* libraries and packages that you want to 
be always available in Racket.



Just as a general rule, you ought not to be working under any directory 
whose name starts with a period.


It is a Unix convention that a file or directory whose name starts with 
a period is private space belonging to some application (which in Unix / 
Linux includes the shell itself).   The convention also holds that these 
objects should not be shown normally in file listings.  However, if you 
specify the "-a" option to "ls"  (or have a shell alias that does so), 
you will see these "hidden" files and directories in your listings.  
["-a" means "all"]



You should set up another directory hierarchy for everyday work.  If / 
When something is stable and you want it to be available in Racket all 
the time, only then should you install it into the collection.


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/2b1bd2a4-7256-bf22-1312-c8405dd95b67%40comcast.net.


Re: [racket-users] Is there a function to find and update all compiled directories?

2020-11-01 Thread George Neuner


On 11/1/2020 9:20 PM, Sam Tobin-Hochstadt wrote:


On Sun, Nov 1, 2020, 9:11 PM George Neuner <mailto:gneun...@comcast.net>> wrote:



On 11/1/2020 6:50 PM, Shu-Hung You wrote:
> Using the command-line instruction `raco setup` will update all
> obsolete bytecodes. If you are looking for a programmable interface,
> `compiler/cm` is a good starting point.

Note that "raco setup" rebuilds *only* Racket's own modules and
installed extra packages - it does not rebuild any programmer code.


`raco setup` rebuilds all collections, including all installed or 
linked packages. This includes "programmer code" if you make it a 
package or collection, which is usually a good idea for anything long 
lived.


Sam



In general I agree with you (although making packages out of everything 
complicates migrations to new Racket versions).   However what I said 
previously is correct:  "raco setup" only rebuilds stuff that is 
directly under Racket's control  (installed packages or collections).


It is not guaranteed to rebuild every Racket based program on your 
system ... and that is what I intended to convey.


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/90429cf8-1ada-9a3d-9413-b973120c98e1%40comcast.net.


Re: [racket-users] Is there a function to find and update all compiled directories?

2020-11-01 Thread George Neuner



On 11/1/2020 6:50 PM, Shu-Hung You wrote:

Using the command-line instruction `raco setup` will update all
obsolete bytecodes. If you are looking for a programmable interface,
`compiler/cm` is a good starting point.


Note that "raco setup" rebuilds *only* Racket's own modules and 
installed extra packages - it does not rebuild any programmer code.


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/99286665-fed0-caeb-6eb0-2cb2cac4969f%40comcast.net.


Re: [racket-users] Which action should I take: (a) go back to using Racket v.7.7 or (b) resolve issues.

2020-11-01 Thread George Neuner



On 11/1/2020 5:10 PM, infodeveloperdon wrote:
I'm nervous. After installing racket version 7.8 on linux (Ubuntu) at 
a time when I really should not have done only because I'm in the 
middle of development and would much prefer to change the version at a 
later date.  The installation did not go without a hitch this time, 
meaning the problem seems to be minor but will take me time to 
resolve. I am inclined to return to version 7.7, if that is possible.
Q. Is it a mistake to simply reinstall racket v.7.7? Does that action 
make it the current version even though version 7.8 is now installed.


On Linux it's better to uninstall the current version before installing 
another (unless you want to install multiple versions in parallel).  The 
main thing is to AVOID a "Unix-style" installation which sticks things 
in many different places.


see https://ostechnix.com/install-racket-programming-language-on-linux/



Q. To change the current racket version should I be using:
a)  raco setup...
or possibly:
b)  raco pkg remove
and
      raco pkg install
Q. I've been reading up on "Getting Started with Packages" but am I 
correct in thinking they are conceptually within a racket version 
rather than the complete definition of a racket version.

Thanks
Don


Sorry, I don't have a lot of use for packages that aren't included in 
the distribution, so I can't help you here.  If you have installed extra 
packages, they DO need to be migrated into (recompiled for) a new Racket 
version.


If you install multiple versions of Racket (in different directories), 
you can just modify your path to reference the one you want.  Or if you 
use DrRacket, create multiple launchers - one for each version.



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/70c541d5-9eac-988a-935c-706b28e3d767%40comcast.net.


Re: [racket-users] After installing new racket version it seems that I need to find and delete all 'compiled' dirs...

2020-11-01 Thread George Neuner

On 11/1/2020 4:37 PM, infodeveloperdon wrote:
How do I avoid the auto-creation of the 'compiled' directory which 
currently occurs every time I create a module?


If you're using DrRacket, it's an option:  under "Language -> Choose 
Language ..."


Select the Racket language and press "Show Details" at the bottom of the 
dialog.  The dialog will expand to show more options at the right, one 
of which is "populate 'compiled' directories".  If you turn that off, 
DrRacket won't create and cache .zo files for your source files.  [You 
still need to delete any that already exist.]



If you are using a different editor, then don't try to build your 
program using "raco"[1].  You can execute your program from the command 
line with "racket "  but you have to rely on 
logging or "print" style debugging.  As your programs get more complex, 
you may also find some racket's command line options[2] to be useful.


George

[1] https://docs.racket-lang.org/raco/make.html
[2] https://docs.racket-lang.org/reference/running-sa.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/50c3ef6f-c210-7cd7-1d47-66fb928e5645%40comcast.net.


Re: [racket-users] After installing new racket version it seems that I need to find and delete all 'compiled' dirs...

2020-11-01 Thread George Neuner



On 11/1/2020 4:45 PM, Robby Findler wrote:
It is true that running just "racket x.rkt" will not notice some 
situations where your .zo files are wrong and thus lead to the bad 
behavior George describes below but I find it quite handy to use .zo 
files during development, as they can speed things up considerably 
depending on what's happening in your application. If you are working 
at the command line and using something like "racket x.rkt" to run 
your program, then changing to "raco make x.rkt && racket x.rkt" will 
keep your .zo files all sync'd up.


Dunno ... too many times debugging in DrRacket I've run into situations 
where having .zo files screwed up tracing calls across modules in 
different source files.


In Racket's defense, I will say I haven't tried to do it with any recent 
versions ... my machines have always been fast, and (other than for 
performance testing or deployments) I gave up on caching .zo files a 
long time ago.


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/a5b8d35c-c21b-4f87-208d-98aa12174a34%40comcast.net.


Re: [racket-users] After installing new racket version it seems that I need to find and delete all 'compiled' dirs...

2020-11-01 Thread George Neuner



On 11/1/2020 11:34 AM, infodeveloperdon wrote:
so that when I run Racket it recreates the 'compiled' directories 
using the latest compiler.

Or is there a better way?


Yeah ... don't use 'compiled' directories for development - they can get 
out of sync and screw up your debugging.


They really are only useful for performance testing or for deployment in 
situations where you don't want to (or can't) build a single executable.


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/b83b03b4-f2a8-2b6c-7ac8-00caa1e6d104%40comcast.net.


Re: [racket-users] Where to specify a previously installed racket version or...

2020-11-01 Thread George Neuner



On 11/1/2020 11:15 AM, infodeveloperdon wrote:

Where to specify a previously installed racket version or...
is the only way to change back from version 7.8 to 7.7 to re-install 
version 7.7?


You can install multiple versions in parallel as long as they are kept 
aprat in separate directory hierarchies.  This is the default on 
Windows, but on Linux be sure to choose an install option that keeps 
everything together and doesn't create extraneous links in the top level 
system directories.


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/bbb875dd-462e-a4bc-bf8e-eb69997c3c78%40comcast.net.


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

2020-11-01 Thread George Neuner
On Sat, 31 Oct 2020 03:25:32 -0700 (PDT),
"jackh...@gmail.com"
 wrote:

>Wow, these are a lot of great responses. First of all, *awesome* job Ryan. 
>That implementation is exactly what I needed to figure out. I'm definitely 
>starting there first.
>
>> Are you looking for `let/ec`?
>
>I'd forgotten about that one. That has the *syntax* I want. However my 
>issue with continuation-based approaches isn't the syntax, or even the 
>performance. It's the semantics. What if someone writes code like this?
>
>(guarded-block
>  (define x (random 10))
>  (thread
>(lambda ()
>  (guard (even? x) else #false)
>  ...)))
>
>If I implemented guarded-block in terms of let/ec, then what does this code 
>even *do*? I honestly don't know. It would probably run without error and 
>do... something. 

(let/ec return
  (thread
   (lambda ()
 (return -1)
 42)))

throws an error:  "continuation application: attempt to jump into an
escape continuation"

There is a continuation barrier between the threads.


However, let/cc works: e.g.,

(let/cc return
  (thread
   (lambda ()
 (return -1)
 42)))

returns -1.


>I am extremely sure that regardless of what it did, it 
>would be confusing and it wouldn't solve any problem I had. 

I am sure it would solve *some* problems.


>I just flat out don't want to allow this or any related nonsense, 
>such as:
>
>; Aliasing
>(define return guard)
>
>; Higher-order usage
>(map guard (some-list ...))
>
>; Capturing via closure
>(guarded-block
>  (define (check-foo x) (guard (foo? x) else #false))
>  (check-foo ...)
>  ...)
>
>; Capturing via mutation
>(set! previous-guard guard)
>
>; Oh great, now I have to think about even more continuation jumps
>(dynamic-wind
>  (lambda () (guard ...))
>  (lambda () ...)
>  (lambda () ...))
>
>There might be valid use cases for some of these, but I certainly don't 
>understand those use cases well enough to commit to a semantics for them.

It always is safe to jump upwards OUT of a lower level computation.
The sticky issues [and mental gyrations] with continuations all have
to do with jumping downwards or sideways.

I'm not sure what problems you might have with continuation barriers:
the example of the thread shows that (upward-only) "escape"
continuations don't work across threads ... but "full" continations do
work, and would still work even if the threads were siblings rather
than in a parent/child relationship.

The issue for your purpose would be making sure the continuation is
called from a position that is guaranteed to terminate the errant
thread: you might need to recognize a thread as a special case, wrap
it and (like an exception) catch/rethrow the continuation.


Or, if you don't care about sibling threads, just use exceptions which
always can be thrown upward out of child threads.

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/2r6upftjom3aipt0g32nkcmikdc37je2t6%404ax.com.


Re: [racket-users] Contracts for (partially) specifying dictionary key -> value-predicates

2020-10-30 Thread George Neuner



On 10/30/2020 3:08 PM, William J. Bowman wrote:

Let me aid this discussion by copying in the ~10 lintes of code in question:

> (define-syntax (dictof syn)
>   (syntax-parse syn
> [(_ (k:id pred?) ...)
>  (quasisyntax/loc syn
>(dictof/proc `((k . ,pred?) ...)))]))
> 
> (define ((dictof/proc spec) h)

>   (and (eq? (dict-keys h) (dict-keys spec))
>(for/and ([(k pred?) (in-dict spec)])
>  (pred? (dict-ref h k)

The macro is merely a syntactic transformation to 1 line of code that implements
the functionality of the contract at run-time.
Is there some reason to avoid macros in this particular case?


There's rarely any problem with macros that only provide syntactic sugar.

The issues wrt contracts are how heavy are the dictionary functions.  
The FOR loop is concerning because the check time is proportional to the 
size of the dictionary  [again recalling that contracts live on in 
release code].


For performance it would be better to enforce the predicate on values as 
they are entered, and then assume anything already in the dictionary is 
correct.  It is sensible to provide a function that validates the whole 
dictionary, but I would make it something the programmer has to invoke 
deliberately rather than a contract to be enforced at (even just 1st in 
module) mention of the dictionary.


YMMV,
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/95997336-33d4-5c5b-b329-9ea691fe59ef%40comcast.net.


Re: [racket-users] Contracts for (partially) specifying dictionary key -> value-predicates

2020-10-30 Thread George Neuner



On 10/30/2020 1:14 PM, William J. Bowman wrote:

Thanks! One follow-up:

> 1. make these functions, not macros
The main implementation is a procedure, but I think I need a macro to get the
syntactic interface I want.

Is there some reason to avoid macros?


You certainly can use macros in the implementation, but just remember 
that macros evaluate at compile time and most contracts have to be 
checked at runtime: so a contract can't *exclusively* be a macro ... 
runtime code has to be generated.


Robby's comment about code size is relevant also:  contracts are not 
debug mode only like assertions in C ... Racket's contracts live on in 
release mode compiles, so you want to minimize the amount of runtime 
code required to implement them.


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/5f5fecff-01f9-5f66-1ffe-4486de354199%40comcast.net.


Re: [racket-users] Clearer code in DrRacket?

2020-10-09 Thread George Neuner


On 10/9/2020 10:11 AM, Adam El Mazouari wrote:

An example is this:

(define (square-all lst) (if (null? lst)

'()
(cons (square (car lst))

(square-all (cdr lst)


As you can see, you've got:

  * methods included by default (define, cons)
  * booleans (null?)
  * user-introduced vars (lst)

shown in the same color. It's really not clear. I'd like for them to 
be in different colors.


--Adam.


The colors of most things in DrRacket are adjustable: see Preferences in 
the Edit menu.  There are several general color schemes and/or you can 
set colors individually for most syntax items.


Note that there are multiple (2nd level) tabs under Color [and also 
under Editing].


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/d343842b-44ee-df36-2ac9-31b3b8e3ead3%40comcast.net.


Re: [racket-users] Pattern Matching

2020-10-06 Thread George Neuner


On 10/6/2020 10:41 AM, Beatriz Moreira wrote:

Hello,

Yes, my idea is to check the type of the parameters. I still have to 
add the types to my code, but I was trying to see if I could do it 
without them (just pattern matching), as the functions of type *f* are 
in the declaration of the contract.


Can you access this link? 
https://bitbucket.org/beatrizmoreira/msc/src/master/fwsollast.rkt 



Thank you for your answer :D


I thought you were working with match in Racket ... Redex is its own 
language, and I haven't done anything with it.


Sorry, I can't help.
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/caef9073-1d94-6799-cfc6-730058cc1c7d%40comcast.net.


Re: [racket-users] Pattern Matching

2020-09-28 Thread George Neuner


On 9/28/2020 10:50 AM, Beatriz Moreira wrote:

Hello,
I would like to know how do I match multiple variables to a regular 
expression.
My idea is to match every *f* variables (f...) to an *f* in ((contract 
C ((T x) ...) ((T f)) ...) ... ).
I am trying to implement a core language for smart contracts in 
Racket, but I need to have as pre condition in my reduction rules that 
the *f* is a function in one of the contracts.

Thank you! :)


'regexp-match*' outputs a list of matched strings, and match has an 
apply clause: '(app /expr/ pats ...)' which evaluates /expr/ and tries 
to match the output.  My first thought would be to try something like:


  match ( inp )
    :
    ((app (regexp-match* pattern inp) match1 match2 ... )
   ... )
    :

Caveat ... I've never tried to do this.  If match doesn't like this 
approach (or something close to it), then I would separately perform the 
regexp-match* and the pattern match on its output list.


Hope this helps,
George

https://docs.racket-lang.org/reference/regexp.html
https://docs.racket-lang.org/reference/match.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/22de3af2-b64f-73c0-fe12-a832dccf6086%40comcast.net.


Re: [racket-users] Why is get-impure-port* slower than a system call to curl?

2020-09-16 Thread George Neuner



On 9/16/2020 5:59 PM, Alex Harsanyi wrote:
On Windows at least, "localhost" resolves to two IP addresses (in this 
order): "::1" (IPv6) and "127.0.0.1".  The Racket `tcp-connect` 
function will try the fist one first, and since you probably don't 
bind your web server to the IPv6 address, the connection times out, 
than `tcp-connect` tries the IPv4 one and succeeds.  This is  why 
using "localhost" is slower than using "127.0.0.1".


I know this because I have been caught by it as well :-)  My solution 
was to learn IpV6 and start my server on IPv6 :-)


 Perhaps curl and Chrome go straight for the IPv4 address.

As a test, try starting your web server on an IPv6 address (::1) and 
see if things improve.


Alex.


That's true - Windows tries IPv6 first - but it isn't the whole story 
here.  If IPv6 were the only cause, then disabling IPv6 should fix the 
problem ... but it doesn't always fix the problem.  On some Windows 
machines, name resolution by the local DNS client is just painfully slow 
[and no one knows exactly why].


Certainly Stephen should try either binding the server to ::1 or 
disabling IPv6 altogether ... but it's possible that neither of these 
options may solve his problem.


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/ba034951-9271-03fa-6d3d-e98879ba7792%40comcast.net.


[racket-users] Re: Why is get-impure-port* slower than a system call to curl?

2020-09-16 Thread George Neuner
On Wed, 16 Sep 2020 08:14:11 -0700, Stephen Foster
 wrote:

>Turns out it's largely a "my system thing": requests to "localhost" are
>slow, but 127.0.0.1 are fast.  On Chrome and curl, both were fast, which is
>why I assumed the slowdown was in some Racket package.  It's more likely a
>DNS issue.  (I have to use an unfamiliar Windows machine for game
>development; there's probably something misconfigured about the DNS.)

Slow "localhost" name resolution is a known issue with Windows.  

It's not a misconfiguration ... at least not in the conventional
sense.  Windows DNS client ignores the HOSTS file wrt "localhost" -
the loopback is hardcoded in the client.

Unfortunately the problem seems to strike randomly: many people never
see it, and no one really knows why it happens or what to do about it.
Flushing the DNS cache sometimes seems to help.

On Win7 or Win8, you could disable the DNS client and use the HOSTS
file exclusively, but Win10 doesn't allow to disable the DNS client
(or even to stop it via the GUI - it can be stopped briefly using the
command line service tool, but it will restart automagically after a
few minutes or if the machine is rebooted).

YMMV,
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/ua25mfl91f5slf8cju64hli557917mrssg%404ax.com.


Re: [racket-users] question about places and main thread gc

2020-09-13 Thread George Neuner


On 9/13/2020 4:12 PM, Nate Griswold wrote:
Sorry, i forgot to mention this would be interfacing on the main 
thread from c


does this still hold true? Like if a c call returns does it kill the 
places?


Nate


I'm not really sure what you are asking:  it sounds like you are wanting 
to embed Racket into a C program ... if that is the case, then the 
primary thread is in the C program and any/all Racket threads will be 
secondary.


I don't know that Racket's place API even works in an embedded 
scenario.  You certainly can create multiple threads within your C 
program and run Racket in them, but it's hard to share a Racket 
environment, and if you create a separate execution environment for each 
thread, then their operations will be independent of one another.


If you just call a Racket function from C, that function will be 
executed in the same thread as the caller, and it will return to the 
caller when it finishes.  Of course that function could have side 
effects such as signaling a separate Racket thread to terminate.


A lot depends on what you are trying to do and how you structure your 
solution.



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/c6d3915d-5c92-ea6a-bedd-5c31a540cc71%40comcast.net.


Re: [racket-users] question about places and main thread gc

2020-09-13 Thread George Neuner



On 9/13/2020 3:55 AM, Nate Griswold wrote:


I am making an app that basically spawns two racket places and i want 
to be able to communicate with them from c code.


Will gc happen in the two racket places if i don't keep the main 
thread (the one that spawned the places) running?


Exiting the main thread kills the process.  "dynamic"[1] places are (OS 
level) threads within the same process and they will die with it.  
[Technically the main thread is itself a place, but normally we don't 
use place  terminology when talking about the main thread unless there 
are other places involved.]


I was thinking about whether i should keep the main thread running and 
block on a stream read, sending it messages, or if i can only call 
into the main thread when i need something using racket/chezscheme 
apis. I guess it would be simpler to just talk directly to the main 
thread when i need to, which is why i'm asking. Otherwise i'm thinking 
of just using zeromq on the main thread.


You certainly can talk to any of the places individually ... but you do 
need the main thread to remain running (even if just waiting on some 
event) if you want dynamic places to continue running.



Now "distributed"[2,3] places are separate processes - you can start 
them and they will continue running regardless of what happens to the 
process that spawned them.



Nate


Hope this helps,
George

[1]  https://docs.racket-lang.org/reference/places.html
[2]  https://docs.racket-lang.org/distributed-places/index.html
[3]  https://pkgd.racket-lang.org/pkgn/search?q=loci

--
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/48c3d0ce-50ed-6ad3-7e03-470335c98474%40comcast.net.


Re: [racket-users] package manager woes on Windows 10?

2020-09-10 Thread George Neuner




On 9/10/2020 10:06 AM, Philip McGrath wrote:
Also, this is happening over encrypted HTTPS: no one is sniffing the 
User-Agent header.


While it may not be the issue here, you need to understand that 
appliance firewalls CAN and routinely DO examine data inside encrypted 
connections.


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/b7faf924-5d4a-0d21-db6c-dee1afde8c61%40comcast.net.


Re: [racket-users] package manager woes on Windows 10?

2020-09-10 Thread George Neuner



On 9/10/2020 7:37 AM, Hendrik Boom wrote:

On Thu, Sep 10, 2020 at 12:49:25AM -0400, George Neuner wrote:
> 
> I don't know if DrRacket even sends a "user agent" string.


If DrRacket can send a user agent string, so can malware.

So it's not really reliable to filter on the user agent string.

-- hendrik


Of course ... any HTTP request can forge a user agent string:  most 
browsers allow you to change it, and so do some HTTP aware 
applications.  E.g., there is a plugin for Firefox that changes it on 
the fly based on the URL - use cases involve things like Google image 
search behaving differently for Chrome vs non-Chrome users, and 
Microsoft sites behaving differently for non-Windows users.


My point is that there may be something unseen - probably a firewall - 
blocking the DrRacket request but not blocking requests from the known 
browser.  If it isn't some software installed on the machine itself, it 
likely is an IT appliance guarding the whole network. Firewall 
appliances are NAT routers: they can look inside even encrypted 
connections to examine protocols being used and the raw data passing 
through.


Based on the error from Shriram's message, it looks like DrRacket is 
successfully calling out but doesn't like/understand the response ... 
which would tend to eliminate Windows built-in firewall as a suspect [it 
doesn't do protocol inspection].  It still could be other AV/firewall 
software on the machine, or something upstream in the network that his 
student is unaware of.


YMMV,
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/8a1628af-b647-5272-1c9a-da347b604091%40comcast.net.


Re: [racket-users] package manager woes on Windows 10?

2020-09-09 Thread George Neuner



On 9/9/2020 10:05 PM, Shriram Krishnamurthi wrote:
Thank you. Can you imagine why the proxy would affect DrRacket but not 
the Web browser?


DrRacket and the browser can be configured independently ... at least 
for a known proxy.    DrRacket's setting is in preferences under 
"browser".  However, if your student is on campus (or at work?), he/she 
may be behind an upstream system-wide firewall or proxy which is unknown.


Commercial firewalls can read request headers and pass/fail based on the 
"user agent" string so as to allow known browsers and other vetted 
applications to operate while rejecting requests from unvetted applications.


I don't know if DrRacket even sends a "user agent" string.

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/40d69d4d-81cc-525f-5bc2-b22a8f6eb50f%40comcast.net.


Re: [racket-users] package manager woes on Windows 10?

2020-09-09 Thread George Neuner



From the error message, it looks like a firewall/proxy issue.

It definitely is not the package itself:  I'm still on Racket 7.7, but 
it works for me.  I tried both with 64 and 32 bit BC on Win10 1909 - the 
package and its dependencies install for me without errors  [but I don't 
know how to test the install  8-)]


George


On 9/9/2020 9:00 PM, Shriram Krishnamurthi wrote:
I have a student using Racket 7.8 on Windows 10 (v. 1909) who can't 
get a package to install that he needs to do homework. Does anyone 
else recognize this phenomenon? Thanks for any advice — none of us has 
Windows so we can't even reproduce this. He has restarted DrRacket, 
confirmed he can connect to the repo via his browser, tried several 
times (so it's not intermittent network outage), confirmed he's 
copying-and-pasting the URL.


It's probably something obvious that I'm just not spotting. Extra eyes 
would be much appreciated given that the clock's ticking on his homework!


The repo in question is

https://github.com/shriram/mystery-languages/
https://github.com/shriram/mystery-languages.git


Thanks!
Shriram



--
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/d856cb76-928f-3d69-d292-1a8f8b1e5240%40comcast.net.


Re: [racket-users] GUI zoom and normal-control-font

2020-08-19 Thread George Neuner

On 8/19/2020 1:37 PM, James Platt wrote:
> 
> On 8/18/2020 12:31 PM, James Platt wrote:

>> I'm looking at implementing a zoom contents (not zoom window) feature in a 
GUI with lots of elements and I'm wondering about the best way to do this.  Most, if 
not all, standard GUI widgets in Racket can be resized by changing the font size of 
their contents or label.   Then redraw the widget and you have the whole thing in a 
new size.  So zoom could be done by creating a function which handles each element 
individually but I would like a more general solution, if possible.  Most widgets use 
the value normal-control-font for their default but it doesn't look like this can be 
changed at present.  If there were a setter for normal-control-font, it looks like 
you could have a menu item change it, then recursively get the children of the frame 
it is attached to and redraw them.  Would this actually work? Is there a better way 
to do it?
> 
> If you can access (or render) the contents as a 'pict', then it be scaled somewhat arbitrarily (though a scaled version is not guaranteed to look good).

> https://docs.racket-lang.org/pict/Pict_Drawing_Adjusters.html
> 
> It is a form of BitBLT operation.  I would search the docs for "blt" or "blit" in addition to "scale" and "size".  Sorry I can't point you more directly to relevant functions:  I've done a lot of GUI programming, but, unfortunately, I know it from C++ using device contexts directly, not from using Racket's graphics.


If I understand correctly, I would do that like in the Stackoverflow post 
below.   Note the need for using the bitmap% version of the button label.   The 
advantage of this approach is that you can change the label dynamically with a 
send.  The drawback is that I would have to create a modified version of every 
widget.  I was just hoping for a solution which would not require so much 
customization of a standard Racket package.

https://stackoverflow.com/questions/48414363/how-to-change-the-color-of-text-in-a-racket-gui-button/48468797#48468797


Sorry, it was not clear to me that you wanted to resize widgets (child 
windows).  Typically when one speaks about a window's "content" they are 
referring to text or imagery drawn onto the window's backing bitmap.


Basically, you need to push a resize message to every child.  I'm not 
sure the best way to do that, but my first thought would be something 
involving panels (or panes).  When a panel gets resized, all its 
children are resized as well.

https://docs.racket-lang.org/gui/windowing-overview.html#%28part._containeroverview%29
https://docs.racket-lang.org/gui/panel_.html
https://docs.racket-lang.org/gui/pane_.html

The trick is that normally a panel would be sized relative to its 
parent.  To effect a "zoom" you would have to override that behavior so 
at least the (Z-stack) bottom panel can be made larger than the 
application window's viewing area.


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/65bbe973-c309-1f92-620a-76d4708f32c7%40comcast.net.


Re: [racket-users] GUI zoom and normal-control-font

2020-08-18 Thread George Neuner



On 8/18/2020 12:31 PM, James Platt wrote:

I'm looking at implementing a zoom contents (not zoom window) feature in a GUI 
with lots of elements and I'm wondering about the best way to do this.  Most, 
if not all, standard GUI widgets in Racket can be resized by changing the font 
size of their contents or label.   Then redraw the widget and you have the 
whole thing in a new size.  So zoom could be done by creating a function which 
handles each element individually but I would like a more general solution, if 
possible.  Most widgets use the value normal-control-font for their default but 
it doesn't look like this can be changed at present.  If there were a setter 
for normal-control-font, it looks like you could have a menu item change it, 
then recursively get the children of the frame it is attached to and redraw 
them.  Would this actually work? Is there a better way to do it?


If you can access (or render) the contents as a 'pict', then it be 
scaled somewhat arbitrarily (though a scaled version is not guaranteed 
to look good).

https://docs.racket-lang.org/pict/Pict_Drawing_Adjusters.html

It is a form of BitBLT operation.  I would search the docs for "blt" or 
"blit" in addition to "scale" and "size".  Sorry I can't point you more 
directly to relevant functions:  I've done a lot of GUI programming, 
but, unfortunately, I know it from C++ using device contexts directly, 
not from using Racket's graphics.


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/c9f51d94-3b70-83fc-14b8-f858fcfed32c%40comcast.net.


Re: [racket-users] Strange performance behavior

2020-08-08 Thread George Neuner



On 8/9/2020 1:20 AM, wanp...@gmail.com wrote:


One more thing which bothers me is if I put a (collect-garbage) in 
front of the testing, I got gc time: 0 if not I got gc time: 9.
Why can't 1 gc reclaim all memory during execution while it can before 
executes?


Those numbers show *time* spent working, not what was done.  If you 
collect before running your program, at that point little has been 
allocated, and little or nothing has been freed, and so the GC has 
little to do ... hence it spends '0' time doing it  [zero meaning below 
the resolution of the computer's clock].  Once your program starts 
running, memory is being allocated and freed, and so a GC in the middle 
or at the end has much more work to do.


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/8499ad0d-a5a7-424b-1027-df25b255bc61%40comcast.net.


Re: [racket-users] Re: Strange performance behavior

2020-08-08 Thread George Neuner



On 8/8/2020 9:45 AM, Matthew Flatt wrote:

At Sat, 8 Aug 2020 03:32:57 -0400, George Neuner wrote:
> 
> On 8/8/2020 1:55 AM, Sorawee Porncharoenwase wrote:
> > I even saw people doing `collect-garbage` three times, just to be safe 
> > I guess. And yet theoretically it's not guaranteed that things will be 
> > claimed back properly.

> >
> > Honestly, there should be a function that does this `collect-garbage` 
> > until fixpoint or something, so that we don't need to perform this ... 
> > uh  ritual.
> 
> There may be no documented guarantee, but I *think* the implementation 
> assures that 2 collections, back-to-back, are sufficient to reclaim all 
> objects that were garbage at the beginning of the 1st collection.  At 
> least for BC Racket.


In the absence of finalization, then a single `collect-garbage` would
always be sufficient, and a second `collect-garage` would have no
effect.

For the specific benchmark in this thread as run in plain `racket`, I
think a single `collect-garbage` is sufficient, and that's what I
normally do.

But finalization complicates the picture --- especially finalization
via `register-finalizer`, since the finalizers run in a background
thread. Because of that background thread, in a context that uses a
library like `racket/gui`, I sometimes use repetitions of

  (collect-garbage)
  (sync (system-idle-evt))


Yes.  But, at least if you use the generational collector, you know that 
once an object has been finalized it will be collected the next time the 
GC looks at it:  i.e. at or before the next major collection.


But there is the issue of incremental GC.  Incremental complicates the 
notion of the GC "cycle" because it interleaves GC with execution of the 
mutator and splits a single "full" collection into many partial 
collections.  I don't know enough about Racket's implementation to say 
whether objects that become garbage *during* a GC cycle can be collected 
in that same cycle, or whether they must wait for the next.



But in truth these details should not matter much except for debugging, 
benchmarking, or for programs that must operate in limited memory.




It's difficult to know whether the libraries that you use rely on
finalization. Also, finalization means that there is no simple number
of `(collect-garbage)`s and `(sync (system-idle-evt))`s that are needed
to really collect everything that could potentially be collected;
finalization chains can require an arbitrary number of
`(collect-garbage)` cycles to clean up (so libraries should avoid
finalization chains!). The collector is precise and the compiler is
safe-for-space, so you can reason about the reachability of an
individual value, but reasoning precisely about overall memory use
across many libraries is difficult or impossible.

Using an extra `(collect-garbage)` is not ideal and often not
necessary, but it's a reasonable just-to-be-sure habit.


Matthew


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/9cb6e5ef-c3f3-2fdd-44a9-88f9e0c9036b%40comcast.net.


Re: [racket-users] Re: Strange performance behavior

2020-08-08 Thread George Neuner



On 8/8/2020 1:55 AM, Sorawee Porncharoenwase wrote:
I even saw people doing `collect-garbage` three times, just to be safe 
I guess. And yet theoretically it's not guaranteed that things will be 
claimed back properly.


Honestly, there should be a function that does this `collect-garbage` 
until fixpoint or something, so that we don't need to perform this ... 
uh  ritual.


There may be no documented guarantee, but I *think* the implementation 
assures that 2 collections, back-to-back, are sufficient to reclaim all 
objects that were garbage at the beginning of the 1st collection.  At 
least for BC Racket.


And I know that sounds like weasle ... but GC efficiency is measured 
statistically, and it's impossible to reclaim 100% of garbage in a 
single collection without completely stopping the mutator for the 
duration.  The whole point of incremental, generational  [and multispace 
in general] collection is to avoid long pauses.


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/245ee574-69e9-d1f8-b2a0-fe1316e542f2%40comcast.net.


[racket-users] Re: Strange performance behavior

2020-08-07 Thread George Neuner
On Fri, 7 Aug 2020 06:23:52 -0700 (PDT), "'Joel Dueck' via Racket
Users"  wrote:

>On Wednesday, August 5, 2020 at 10:44:21 AM UTC-5 Sam Tobin-Hochstadt wrote:
>
>> Here's a benchmark of your two functions that takes long enough to run 
>> that it avoids some of these issues, and also runs a GC before 
>> benchmarking: https://gist.github.com/7cb4645308d8572e2250833ef7b90b7c 
>>
>
>What is the reason for calling `collect-garbage` twice consecutively? 

It is an attempt to start with the cleanest heap possible.  

Objects that have a "finalizer" get collected over 2 GC cycles - the
finalizer function gets run during the 1st collection, and then the
object memory is reclaimed during the next collection.

Running GC twice makes sure any finalized objects have been collected.


Also, when GC can run in parallel with the mutator, it is possible to
miss collecting objects that become garbage *while* GC is running.
This can't happen in BC Racket, but it might be possible in RacketCS
because Chez has a different thread model. ???


>Also, the docs are unclear on this, but is `(collect-garbage)` equivalent 
>to `(collect-garbage 'major)` ?

The docs clearly state that the default is 'major.

 (collect-garbage [request]) ? void?
   request : (or/c 'major 'minor 'incremental) = 'major


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/tp8sifhd4c0cdlvk22qfsmksckv5r0ajpq%404ax.com.


[racket-users] Re: Strange performance behavior

2020-08-06 Thread George Neuner
On Wed, 5 Aug 2020 08:21:07 -0700 (PDT),
"wanp...@gmail.com"
 wrote:

>I was working on a exercism problem named Raindrops.
>
>  :
> 
>I thought version 1 would be faster, but it turned out to be wrong. Running 
>with raco test got following timing information.
>
>version 1
>cpu time: 9 real time: 9 gc time: 9
>version 2
>cpu time: 0 real time: 0 gc time: 0
>
>Then I ran both version in DrRacket, both output following result.
>cpu time: 0 real time: 0 gc time: 0
>
>It's strange, isn't it?

It looks like the time for the 1st version was skewed by a garbage
collection during execution.

Generally for a decent benchmark, you need to run the code many times
and average the results.  For Racket, additionally you need to
*exclude* the time for the 1st run because that will include time for
JIT compilation.

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/csmnifpho2kgr9sme0psdd0729ui9isdhb%404ax.com.


Re: [racket-users] Re: Racket CS release plan

2020-08-01 Thread George Neuner



On 8/1/2020 3:48 PM, Sam Tobin-Hochstadt wrote:
Note that Matthew's point was not about bytecode, but about the 
machine code in the Racket BC executable vs the machine code in the 
Chez kernel plus boot files. Especially if you look pre-7.0, there is 
very little bytecode in the Racket BC executable.


Sam


Got it.  I missed the context when I read Matthew's message.

However, my comment about average code size remains:  If the Chez code 
uses explicit length prefixes on all instructions that allow them (so as 
to be unambiguous about intent) ... and the GCC code for the BC version 
does not ... then the Chez code EASILY could be much larger.


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/f6c28acb-83db-7c11-8dc0-011429ec6efe%40comcast.net.


Re: [racket-users] Re: Racket CS release plan

2020-08-01 Thread George Neuner

Hi Matthew,

On 8/1/2020 2:01 PM, Matthew Flatt wrote:

At Sat, 01 Aug 2020 03:56:36 -0400, George Neuner wrote:
> On Fri, 31 Jul 2020 20:20:05 -0700 (PDT),
> "wanp...@gmail.com"
>  wrote:
> 
> >I noticed that the size of the CS version is 244% compare to BS 
> >version. Wondering why it became so large. Does that mean Chez Scheme 
> >runtime/vm 100 MB larger than the original one?

> >
> >Racket Mac OS X
> >  64-bit Intel 116.7 MB SHA1: 521b5a264afcfb3f390afacc682987268f650a25
> >
> >Racket CS Mac OS X
> >  64-bit Intel 285.8 MB SHA1: 060f311fc6621c5797a62f98b743499fa4277793
> >
> >https://pre-release.racket-lang.org/
> 
> 
> The CS version compiles to native code rather than portable bytecode,

> so pretty much everything in the distribution is somewhat larger.  It
> adds up quickly.

That's still the best explanation I have, but I also think there must
be something more to it.

For example, the Chez Scheme boot files in uncompressed form add up to
about 8 times the size of compiled Racket BC executable, but Chez
Scheme doesn't have 8 times the functionality of the Racket BC
executable (so it should have 8 times as much machine code). The
machine code generated by Chez Scheme for its boot files is less
compact than machine code generated by GCC or LLVM for Racket BC's
implementation --- but, again, I don't think it's a factor of 8. So,
I'm optimistic that I've so far overlooked something that can make a
big difference.

I've concentrated more on understanding the difference in the run-time
memory footprints, and the difference there is not nearly so large.
Racket CS now sometimes has a smaller memory footprint than Racket BC
(e.g., peak memory use for a distribution build).

Matthew


I don't know details of the Racket bytecode, but I'm assuming that it is 
a mix of simpler operations that map directly to one or a few native 
instructions, and more complex operations that compile to (the 
equivalent of) a small function.  Probably some of these functions can 
be inlined, but I expect there still would be some that can't.


To understand the difference in code size, you would need to look at the 
lengths of bytecode instructions vs their native code equivalents, and 
account for instances of those operations that can be inlined and for 
calls to the functions for operations that can't.



As I said above, I don't know details of Racket bytecode, but a lot of 
virtual machines use 8 or 16 bit opcodes and (allowing for immediate 
operands) have average instruction lengths of 3..4 bytes. Contrast this 
with, e.g., x86-64 code in which the average instruction is 5..6 bytes  
[larger if many instructions require length prefixes (e.g., 32-bit ops 
in 64-bit code)].  The difference can add up very quickly.


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/c3324f5f-19cd-1e0f-3d83-08787474bede%40comcast.net.


[racket-users] Re: Racket CS release plan

2020-08-01 Thread George Neuner
On Fri, 31 Jul 2020 20:20:05 -0700 (PDT),
"wanp...@gmail.com"
 wrote:

>I noticed that the size of the CS version is 244% compare to BS 
>version. Wondering why it became so large. Does that mean Chez Scheme 
>runtime/vm 100 MB larger than the original one?
>
>Racket Mac OS X
>  64-bit Intel 116.7 MB SHA1: 521b5a264afcfb3f390afacc682987268f650a25
>
>Racket CS Mac OS X
>  64-bit Intel 285.8 MB SHA1: 060f311fc6621c5797a62f98b743499fa4277793
>
>https://pre-release.racket-lang.org/


The CS version compiles to native code rather than portable bytecode,
so pretty much everything in the distribution is somewhat larger.  It
adds up quickly.

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/mp6aifl0f4rtb5dqmmbu4an5i414j5ci78%404ax.com.


Re: [racket-users] “If you could have a wish granted, what would you like to see next in Racket?”

2020-07-23 Thread George Neuner


Hi Laurent,

No, "sandboxing" isn't what I want - at least not usually.  I want to be 
able to limit the VM process itself ... particularly the heap size but 
occasionally other things as well.  I often have the need to squeeze a 
Racket application into the corner of a small cloud VM, and I would like 
is more fine-grained control over Racket processes.


Also, sandboxing only notices the overrun when it's too late.  If the 
memory is known limited from the beginning, it would be used 
differently, e.g., GC'd more often.



Without a lot of details about the memory use of various features[*], 
"ulimit -H -d ..." at best is a guess.  "ulimit -H -m ..." works to 
limit memory use, but it can't be used without swap, and without 
limiting the data segment as well, it's easy to start thrashing code vs 
data and kill performance.


"cgroups" helps with multiprocess applications, but it is complicated to 
set up properly.


But in Windows there is no built-in user control for resource use ... 
there are some 3rd party utilities, but many admins won't permit using 
them.  I work a lot with various DBMS, and things may get easier as SQL 
Server is available for Linux, but most people who run it still run it 
on Windows.



And, of course, containers can limit (at least) memory and CPU, but they 
have their own sets of issues, and the container system itself can 
require substantial resources.  Generally I prefer to avoid containers 
and run on the bare machine wherever possible.


YMMV,
George


[*] particularly JIT:  e.g., application mapped files are "data" from 
the POV of the OS regardless of whether the mapping is executable.  So 
JIT'd code really is data for "ulimit" purposes.




On 7/23/2020 12:47 PM, Laurent wrote:

Just in case (not sure how relevant this is to you):
https://docs.racket-lang.org/reference/Sandboxed_Evaluation.html?q=with-limits#%28form._%28%28lib._racket%2Fsandbox..rkt%29._with-limits%29%29
Works pretty well, but there are some caveats: if an object can be 
reached outside of the `with-limits` scope, it's not counted.


On Thu, Jul 23, 2020 at 5:42 PM George Neuner <mailto:gneun...@comcast.net>> wrote:



Limits on resources used by individual VMs.  ulimit works only at the
process level (so only indirectly affects in-process "thread"
places),
and Windows has no simple equivalent:  I am aware of Windows "job
objects", but there are no user controls for them.



--
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/7ef2f992-076d-1f0e-a36c-243fd810ad3d%40comcast.net.


Re: [racket-users] “If you could have a wish granted, what would you like to see next in Racket?”

2020-07-23 Thread George Neuner



On 7/23/2020 8:30 AM, Stephen De Gabrielle wrote:
“If you could have a wish granted, what would you like to see next in 
Racket?”


https://www.reddit.com/r/Racket/comments/hwe49b/if_you_could_have_a_wish_granted_what_would_you/?utm_source=share_medium=ios_app_name=iossmf 
or [original 
twitter](https://twitter.com/racketlang/status/1286020900660404232?s=20)




SIMD ops.  !!!

Limits on resources used by individual VMs.  ulimit works only at the 
process level (so only indirectly affects in-process "thread" places), 
and Windows has no simple equivalent:  I am aware of Windows "job 
objects", but there are no user controls for them.



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/8b3d3265-616d-e93e-4cd3-01b3ca91a474%40comcast.net.


Re: [racket-users] reading s-expressions from a file

2020-07-17 Thread George Neuner


On 7/17/2020 8:19 PM, Hendrik Boom wrote:

Yes,  I know the functino for reading s-expressions seems to be (read [in]).

I want a loop that reads S-expressions and does something to each one, until 
there are no more to be found in a file.

Now of course that's absurdly easy to do with a tail-recursice loop.

But I's like it to look like a loop, with (for ...) or (while ...) or
(loop ...) or something like that.

But I fail to fine any iterators that process a file, such as (in-file
...)

There's a long list of iterators in
https://docs.racket-lang.org/reference/for.html
and in
https://docs.racket-lang.org/guide/for.html

An I just looking in the wrong place, or are there really no iterators
for reading a stream of s-expressions from a file.

-- hendrik


This should work if you're reading the sexprs for value:

(with-input-from-file /filename/
  (lambda ()
    (for [(expr (read))]
  :
    )))

If your intent is to read/parse the sexprs as text, there isn't a simple 
way to do that.  Regex is problematic for nested expressions ... you 
could try "read-syntax" if you are familiar with macros, or "match" if 
you know what patterns to look for.


There's no "in-match" sequence, so if you want a loop that *appears* 
simple [match in the /"for-clause"/], you'll have to write some glue: a 
helper that returns one match result at a time so as to plug nicely into 
a loop.


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/7184da64-a388-91bf-e027-a213a3d66c73%40comcast.net.


Re: [racket-users] Best data structure for ordered data set with insertion and reordering?

2020-07-16 Thread George Neuner


Hi David,

On 7/16/2020 11:44 AM, David Storrs wrote:
On Thu, Jul 16, 2020 at 10:09 AM George Neuner <mailto:gneun...@comcast.net>> wrote:



The problem seems under-specified.  Can you say more about the
real purpose?


Basic version:  It's a peer-to-peer encrypted swarmed file sharing 
system that presents like Dropbox on the front end (i.e. "make a 
change to the filesystem on peer A and peers B-Z will replicate that 
change") and works something like Bittorrent on the back end in that 
files are sent in chunks but it offers functionality that Bittorrent 
does not, such as encrypted transfer, WoT authentication, etc.


Interesting.  So I'm guessing your problem is to (compactly) represent 
the state of the shared space.


Do you plan on having index servers, or are you aiming for a fully 
distributed solution?  And, if distributed, do you want each node to 
maintain its own state picture of the shared space, or were you thinking 
that nodes could just snoop admin broadcasts looking for mention of data 
they don't currently have?  [Your question about how to pair / collapse 
messages suggests you might be considering a snoopy solution.]


Asking because keeping a state picture has scalability issues, a snoopy 
solution has complexity issues, and (depending on latency) both have 
issues with performing unnecessary work.  In any event, I have some 
suggestions.




Snoopy is the more interesting case.  You start with a queue of file 
operations to be done as gleaned from the admin messages - mkdir, rmdir, 
fetch a file, delete a file, etc. - in whatever order the messages were 
received.


Separately, you maintain a (hash table) mapping from pathnames to a list 
of queue nodes that operate on that object.  The map should use weak 
references so that nodes can safely be removed from the queue and 
discarded without also needing to update the map.  If queue processing 
gets to some operation first, any map reference to it will dissolve (be 
replaced by #f).


When a message is received, you lookup the pathname in the map, and if a 
complementary operation is found in the queue, you remove and discard 
it.  [You can also remove references in the map or just let them 
dissolve depending on your handling.]   Then simply discard the message.


Otherwise you queue whatever operation the message indicates and add a 
reference to the queue node under the object's pathname in the map.


Extra complexity comes in having to notice that map entries (pathnames) 
have no operations left in the queue.  Weak references don't just 
disappear - they are changed to #f when the referenced object is no 
longer reachable - however AFAICT there is no hashtable variant that 
permits weak reference values, so you have to use weak-boxes and those 
continue to exist even if the objects they reference are gone.   Useless 
map entries will need to be identified and removed somehow.



Modeling the filesystem can be done rather simply with a trie in which 
folders are represented by mutable hash tables and files by structures.  
You can combine this with the operation queue above, but in this case 
lookups can be done in the trie and queue references kept in the trie 
nodes.  And the trie provides a snapshot of the current state which may 
be useful for other purposes.



The trick in either case is processing latency: you don't want to wait 
too long, but if you really want to avoid unnecessary work you need to 
delay performing file operations long enough that complementary messages 
are likely to be received.





What if messages are lost permanently, e.g., due to hardware crash?


What it you receive a create but a corresponding delete or update is
lost - then your information / picture of the file system state is
wrong.

What if you receive a file delete without a corresponding create?
In the
absence of other information, can you even assume there *was* a
create?
If these messages are sent in response to user actions, can they
ever be
sent mistakenly?


The ultimate answer to these questions is "If things get out of sync 
in a way that the system cannot resolve, it will be flagged for a 
human to resolve." There are things we do that mitigate them -- for 
example, a write-ahead log for messages received from peers -- but we 
acknowledge that we cannot resolve 100% of situations automatically.  
Neither can any other file replication service.  (Dropbox, Box.com, etc)


Also relevantly, differences are reconciled across multiple peers.  If 
there's 5 peers in your replication set and the other 4 agree that 
there should be a file at path P but you don't have one then it's safe 
to assume that you missed a File-Create message.  And yes, that comes 
with issues of its own (Q: What if it was deleted on your machine and 
none of the others got your File-Delete because you crashed before 
sending it? A: Worst case, the file gets recreated and the user 

Re: [racket-users] Best data structure for ordered data set with insertion and reordering?

2020-07-16 Thread George Neuner



On 7/16/2020 4:29 AM, David Storrs wrote:

tl;dr
Can anyone recommend a data structure that is ordered and supports 
efficient reordering, insertion at arbitrary location, and deletion?


Long form:

I'm working on an operation-log reconciliation problem, where each 
operation is one of:


  File-Create    P H
  File-Update   P H
  File-Delete    P H
  Folder-Create P
  Folder-Delete P

P = path
H = hash of the file (e.g. md5)

Operation messages travel over the network, meaning that they could 
arrive out of order.  (They could also be missed entirely, but that's 
a separate problem that I'm not working on yet.)


Shouldn't be a problem:  "at-least-once" and "at-most-once" semantics 
both are pretty easy.  It's the "exactly-once" that is the problem.  
Hopefully you have no need for that.



Specifically, I want to be able to take a series of messages and 
collapse them where appropriate.  For example:


  File-Update P H1 -> H2
  File-Create P1 H1
Result after collapse:
  '(File-Create P1 H2)

  File-Create P H1
  File-Delete P H1
Result after collapse:
  '()

  File-Delete P X
  File-Create P X
Result after collapse:
  '()
  File-Delete P1 H1
  File-Create P2 H2
  File-Create P1 H1
Result after collapse:
  '(File-Create P2 H2)

I've been mulling over various ways to handle all of this and digging 
around to find examples of other people doing it, but I'm wondering if 
there's a data structure or existing algorithm that will handle it 
cleanly.  Does anyone know of such a thing?


What if messages are lost permanently, e.g., due to hardware crash?

What it you receive a create but a corresponding delete or update is 
lost - then your information / picture of the file system state is wrong.


What if you receive a file delete without a corresponding create? In the 
absence of other information, can you even assume there *was* a create?  
If these messages are sent in response to user actions, can they ever be 
sent mistakenly?


The problem seems under-specified.  Can you say more about the real purpose?


I can think of some ways to keep an index of the file system and track 
changes made to it ... but at best that could provide a snapshot in time 
rather than an ongoing audit log.  And it seems like a log would not be 
terribly useful without all the information.


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/e5bfead8-20cc-47b5-3f10-6a568aa04ba9%40comcast.net.


[racket-users] Re: Are Regular Expression classes Unicode aware?

2020-07-09 Thread George Neuner
On Thu, 9 Jul 2020 14:43:03 -0400, Philip McGrath
 wrote:

>On Thu, Jul 9, 2020 at 10:32 AM Sorawee Porncharoenwase <
>sorawee.pw...@gmail.com> wrote:
>
>> Racket REPL doesn’t handle unicode well. If you try (regexp-match?
>> #px"^[a-zA-Z]+$" "héllo") in DrRacket, or write it as a program in a file
>> and run it, you will find that it does evaluate to #f.
>>
>See this issue for workarounds, including installing the `readline-gpl`
>package: https://github.com/racket/racket/issues/3223
>
>But you may have some other issues: for me, `(regexp-match?
>#px"^[a-zA-Z]+$" "h\U+FFC3\U+FFA9llo")` gives an error saying "read-syntax:
>no hex digit following `\U`"

It works if you remove the '+' sign.  \U and \u are defined to take
hexidecimal values, which are unsigned.  For comparison, \x fails with
the same error if the value is signed.

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/ge0fgflkfkh679e5v8uk9udr3hj0mhvf8h%404ax.com.


Re: [racket-users] Layout + styling in racket/gui

2020-07-06 Thread George Neuner



On 7/6/2020 5:54 PM, Travis Kiefer wrote:

Hello all!

I'm coming from the background of building web apps that are wrapped 
in a headless browser and would like to take the app development 
experience and bring it to the racket ecosystem. As an html / css / 
javascript engineer I'm finding the learning curve pretty daunting 
with racket's documentation but lack of copious examples... So I'd 
like to create some practice apps that introduce ideas / concepts that 
are familiar from the web app realm within the environment of racket...


That said, what I'd like to do is build the canonical "Todo App" in 
racket/gui or an equivalent. Basically I'd like the ability to create 
the equivalent of div / layout elements, sub elements that you are 
familiar to the browser (text input, checkboxes), and the ability to 
mix in styles. Basically HTML + CSS.


Ideally I'd like to create a Racket version of the following 
website: http://photonkit.com.


Any resources to get started would be great.

Best,
Travis


There is a basic GUI layout editor called "MrED".  It's not included 
with Racket, but it is available as an installable package:

   https://pkgs.racket-lang.org/package/mred-designer
http://planet.racket-lang.org/display.ss?package=mred-designer.plt=orseau

The 1st link is newer, but AFAICT doesn't include the documentation.  
2nd link is to the older package server, but includes documentation.



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/1ba3c824-f7bf-81d9-2246-e9d7bc13c862%40comcast.net.


Re: [racket-users] Creating .dmg for a GUI application

2020-07-06 Thread George Neuner



On 7/6/2020 12:48 PM, Travis Kiefer wrote:

Hello all!

Relatively new to the Racket ecosystem and trying to figure out how to 
create an "app" from the GUI library. Has anyone written a tutorial on 
this or have suggestions on where to start to generate this? For 
context, I'm used to the Javascript ecosystem and have built apps with 
Electron. I'm looking to migrate to a more robust lisp-y environment 
when developing native apps and not sure where to start here.


Any help would be greatly appreciated!

Thanks,
Travis


The simplest way is to select "Create Executable..." from the "Racket" 
menu in DrRacket.  Select "GRacket" as the base if your program uses a 
graphical interface.


For more options, see the "raco" command line tool: 
https://docs.racket-lang.org/raco/index.html



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/48e68181-b3bd-4cfe-a30b-7be67109fb60%40comcast.net.


Re: [racket-users] Wills, plumbers, and checking if a port is closed

2020-06-30 Thread George Neuner



On 6/30/2020 4:27 PM, David Storrs wrote:
I have a port that (my current theory says) is being closed when it 
shouldn't, but I'm having trouble isolating exactly where and when.  I 
thought maybe I could do something Rackety to say "as soon as this 
port gets closed, run this function".  I went digging through Wills 
and Plumbers but I'm having trouble grokking it.  Am I headed in the 
right direction, or is there a better way?


Ports are able to raise events.  I don't know if any of these are 
directly useful to diagnose your early close problem, but you may be 
able to cobble something using multiple events.


https://docs.racket-lang.org/reference/sync.html
https://docs.racket-lang.org/reference/port-lib.html?q=port#%28part._.Port_.Events%29


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/47967210-b87b-7a94-a9e2-035a8159e380%40comcast.net.


Re: [racket-users] Why does this counter behave differently in different runtimes?

2020-06-17 Thread George Neuner



Sorry for the noise:  it behaves as you say returning "!", "2", ...    
Somehow I paths screwed up and was running CS when I thought I was 
running regular (bytecode) Racket.


Sigh!
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/abbcdae5-f88e-8a4c-f48b-c6f4fb6be38c%40comcast.net.


Re: [racket-users] Why does this counter behave differently in different runtimes?

2020-06-17 Thread George Neuner


It seems to work ... i.e. returns # ... in Windows.  I tried it in 
7.6 and 7.7,  both 32 and 64 bit versions.   Not near my Linux machine 
to try it there.


The expansion in all cases is the same and seems reasonable:

   (module count racket
  (#%module-begin
   (module configure-runtime '#%kernel
 (#%module-begin (#%require racket/runtime-config) (#%app
   configure '#f)))
   (#%provide count!)
   (define-values
    (lifted/2)
    (begin
  (with-continuation-mark
   contract-continuation-mark-key
   (#%app cons idB12 'no-negative-party)
   (let-values ()
 (#%app
  idX9
  (#%app
   module-name-fixup
   (#%app
    variable-reference->module-source/submod
    (#%variable-reference))
   (#%app list)))
   (define-values
    (count!)
    (let-values (((i) '0))
  (lambda () (begin0 (set! i (#%app add1 i)) (#%app lifted/2
   i)))



Btw:  my Racket installations report only  "7.7", not  "7.7.0.5". Are 
you running a snapshot build?


George


On 6/17/2020 3:04 AM, Sage Gerard wrote:
I attached a video demonstrating what I'm seeing. In case it does not 
load or is not available, I'll summarize here. Forgive any typos; it's 
been a late night of coding.


Here's a module with an incorrect counter. It's incorrect because it 
uses begin0, and is therefore expected to return void instead of an 
incrementing integer.


#lang racket
(provide count!)
(define count!
  (let ([i 0])
    (λ () (begin0
    (set! i (add1 i))
    (~v i)

Notice that I added the ~v to format the return value. If I launch 
Racket v7.7.0.5 using racket -it prog.rkt, (count!) returns the 
formatted value. But if I remove the ~v, it behaves as written 
(returning void).


The video shows the behavior with and without ~v, both in DrRacket and 
racket. DrRacket is the only environment that consistently runs the 
code correctly.




--
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/626cee23-fa67-c17f-781c-44554a50cf2e%40comcast.net.


Re: [racket-users] Re: [racket] Web Framework Benchmarks

2020-06-09 Thread George Neuner



On 6/9/2020 8:11 AM, Jon Zeppieri wrote:

On Tue, Jun 9, 2020 at 7:59 AM Bogdan Popa  wrote:
>
> I think we'd need to also set `SO_REUSEPORT', which is not available on
> all platforms, to support multiple processes listening on the same port
> without reusing file descriptors.

And even where it is available, it doesn't work the same way. The
Linux version can be used to load balance accept()s across processes,
but the BSD version (also in OS X) cannot. (FreeBSD apparently has a
variant, SO_REUSEPORT_LB, that behaves like the Linux version of
SO_REUSEPORT.)


And Windows has 2 options that mean essentially the same thing: 
SO_REUSE_UNICASTPORT  and  SO_PORT_SCALABILITY.


SO_PORT_SCALABILITY  was introduced in Windows 7 / Server 2008.
SO_REUSE_UNICASTPORT  was introduced in Windows 10.

Whichever port reuse option is supported by the platform, it normally is 
set automagically whenever  SO_REUSEADDR  is specified. Only functions 
that require an explicit bind need it to be set manually.




It's clear that enabling the functionality would have to be studied 
carefully.


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/908a290c-75a3-30f0-515f-b93ade3ac103%40comcast.net.


Re: [racket-users] Re: [racket] Web Framework Benchmarks

2020-06-09 Thread George Neuner



On 6/9/2020 7:59 AM, Bogdan Popa wrote:

George Neuner writes:

> Multiple Racket applications *should* all be able to listen on the
> same port without having been spawned from the same ancestor process.
> If that isn't working now, something has gotten hosed.

I don't know whether this used to work in the past or not, but currently
only `SO_REUSEADDR' is set on TCP sockets:

https://github.com/racket/racket/blob/60bf8f970e97caae391bfe919b78c370b2d01bdd/racket/src/rktio/rktio_network.c#L1427

I think we'd need to also set `SO_REUSEPORT', which is not available on
all platforms, to support multiple processes listening on the same port
without reusing file descriptors.


It has been discussed before, but perhaps now, with RacketCS imminent, 
the socket functions should be changed / expanded to allow changing 
options without resorting to FFI.


AFAICS, the functionality of SO_REUSEPORT (if not the verbatim option) 
is available on all supported platforms.  Granted it is (relatively) a 
recent addition to both Linux and Windows.


Android doesn't support it, but AFAIK, Android is not considered a 
supported system.




> I'm not sure what you mean by "sharing" a listener,  but using a
> single listener with a pool of processing places actually is possible
> (though tricky).

I mean passing a `tcp-listener?' around between places so that each
place can call `tcp-accept' on it.  Something like this:

 #lang racket/base

 (require racket/place
  racket/tcp)

 (define ch
   (place ch
 (define listener (place-channel-get ch))
 (tcp-accept listener)
 (place-channel-put 'ok)))

 (module+ main
   (define listener
 (tcp-listen  512 #t))
   (place-channel-put ch listener)
   (place-channel-get ch))

Currently, this fails with:

 place-channel-put: contract violation
   expected: place-message-allowed?
   given: #
   context...:
 ...

My understanding is that there's nothing preventing this from working
apart from the fact that no one's yet added support for this in the
rktio layer.  As you mentioned, though, even if this was supported we
might run into other limitations when running many places at once.


Only serialized[1] functions can be passed between place ... and the 
receiving place still has to have imported the libraries (if any) 
necessary to understand it.  I don't know if a listener even can be 
serialized, though ... AFAIK a serializable function has to be compiled 
that way.


George

[1]  https://docs.racket-lang.org/web-server-internal/closure.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/ea9627a2-34d7-0c09-8246-32fd2d955c25%40comcast.net.


Re: [racket-users] Re: [racket] Web Framework Benchmarks

2020-06-09 Thread George Neuner



On 6/9/2020 3:02 AM, Bogdan Popa wrote:

Alex Harsanyi writes:

> Question 1: Based on this benchmark, is there any reason to chose anything
> else but "drogon"?  Even if one chooses the second best on that list, which
> is "actix", they already loose about 6% performance and things degrade
> quickly afterwards.  The framework at position 10 is already half the speed
> of the top one.

My take on these benchmarks is all that matters is that the framework
doesn't get in your way once you add business logic.  The vast majority
of "real" web applications out there don't (and most likely can't) do
50k rps.


Or anywhere close to that given more realistic database queries.



You can see that in the "multiple queries" and "data updates" tests
where the results are packed closer together because the logic is closer
to what a lot of database-backed web applications do and the database
ends up being a bottleneck.  A description of the requirements of each
test can be found here:

https://github.com/TechEmpower/FrameworkBenchmarks/wiki/Project-Information-Framework-Tests-Overview

If you know and are willing to deal with writing and maintaining C++
then drogon looks like it might be a great choice.

> Question 2:  Based on Bogdans message in this thread, it seems that most of
> the performance improvement for the Racket benchmark comes from the nginx
> configuration (which has nothing to do with Racket) and the next
> improvement has to do with how the user program is written (by supplying a
> "Content-Length" header).  So, is this benchmark really testing the Racket
> web server performance, or is it testing a very specific deployment?

The largest improvement comes from making the Racket application take
advantage of all the hardware threads on the machine.  Because Racket
doesn't currently have a way to share TCP listeners across places and
because fork isn't natively supported (I mentioned that it works via the
FFI earlier in the thread, but I believe it needs some support from the
runtime (handling of `EAGAIN') to work efficiently and not cause a lot
of churn) I did the next best thing: I made the benchmark run one Racket
process for each thread[1] and added nginx as a load balancer in front.

The nginx process listens on port 8080, forks one subprocess per core
(which lets the subprocesses reuse the same port) and then proxies any
incoming requests on that port to one of the Racket processes so every
single request is ultimately served by the Racket app.  What this means
in terms of this benchmark is that, compared to others, we're actually
paying a toll for using nginx here because its own workers are consuming
resources on the machine, but, to my knowledge, we don't have a better
alternative at the moment.


Hmm.  SSL which can be tricky to set up right for Racket, but that's the 
only reason I can see for using a separate HTTP server. Multiple Racket 
applications *should* all be able to listen on the same port without 
having been spawned from the same ancestor process.  If that isn't 
working now, something has gotten hosed.


I'm not sure what you mean by "sharing" a listener,  but using a single 
listener with a pool of processing places actually is possible (though 
tricky).  TCP ports can be passed among places, so a single listener 
instance can direct multiple processing instances.  I don't know how 
passing off the port would interact with web-server response handling (I 
would think the listener place could just shut down / abandon the port 
and leave response to the process place but I have never actually tried 
that).


Dynamic (thread in process) places seem to have issues when there are 
many instances, so for lots of cores it is better to use distributed 
(parallel process) places.  Paulo Matos's  Loci  package makes using 
process places much easier [and it also works on Windows if that matters].

https://pkgs.racket-lang.org/package/loci



[1]: 
https://github.com/TechEmpower/FrameworkBenchmarks/blob/988f052c8170da661c49dd51d1f33d500a871031/frameworks/Racket/racket/scripts/run#L15-L19


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/b763ea64-6319-b162-747b-825cf1cabcb9%40comcast.net.


Re: [racket-users] Re: [racket] Web Framework Benchmarks

2020-06-01 Thread George Neuner



On 6/1/2020 4:21 PM, Bogdan Popa wrote:

George Neuner writes:

> But Python's DB pool is threaded, and Python's threads are core
> limited by the GIL in all the major implementations (excepting
> Jython).

Python's Postgres pooling does not[1] use POSIX threads under the hood
to manage the connections if that's what you mean, nor is the
concurrency of the Python applications based on system threads.  All of
the Python examples use either asyncio + fork(2) or green threads +
fork(2).  This includes the django example[3].


I said nothing whatsoever about POSIX.  And FYI, POSIX does not imply 
any particular implementation - POSIX specifies only the API, and a 
compliant implementation may provide kernel threads, user space threads, 
or a combination of both.


What I did say is that Python's threads are core limited - and *that* is 
true.   As a technical matter, Python *may* in fact start threads on 
different cores, but the continual need to take the GIL quickly forces 
every running thread in the process onto the same core.




> There are a few things Python can do faster than Racket, but the VAST
> difference in performance shown in the techempower tests isn't
> explained by them.

Here's a benchmark that doesn't touch the DB at all, showing an even
bigger difference in throughput between the two:

https://www.techempower.com/benchmarks/#section=data-r19=ph=json


That one actually is expected:  Racket's JSON (de)serializer is 
relatively slow.



What wasn't expected was Sam's results from the "plain text" test which 
also showed Racket much slower than Python.  That does hint at a lot of 
overhead in the Racket framework.




I wrote the latest implementation of the Racket code for that benchmark
and I considered doing things like bypassing the "standard"
`dispatch/servlet' implementation to avoid the overhead of all the
continuation machinery in the web server, but that felt like cheating.


To my knowledge, continuations will not be a factor unless either 1) the 
application is written in the #web-server language (which converts 
everything to CPS), or 2) the code invokes one of the send/suspend/*  
functions.


FWIW: I try to avoid using client facing continuations in my own web 
applications - for my money there are too many uncertainties connected 
with them.


Also the stuffer does a fair amount of work to deal with long 
continuation URLs.




Another area where the web server does more work than it should is in
generating responses: the web server uses chunked transfer encoding for
all responses; whereas all the Python web servers simply write the
response directly to the socket when the length of the content is known
ahead of time.


My understanding is that the port passed to  response/output  is the 
actual socket ... so you can front-end it and write directly.  But that 
might be "cheating" under your definition.



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/2fd131be-ca0e-eaa1-6595-d31a410d43d4%40comcast.net.


Re: [racket-users] Re: [racket] Web Framework Benchmarks

2020-06-01 Thread George Neuner



On 6/1/2020 3:40 PM, Sam Tobin-Hochstadt wrote:

I'm skeptical both of the DB explanation and the multi-core
explanation. As you say, the difference between something like Django
and Racket is much too large to be explained by that. For example, on
the "plaintext" benchmark, Racket serves about 700 req/sec (I get
similar results on my machine). Many of the benchmarks in languages
like Python and Ruby do more than 1000x better, which means that even
if we had perfect speedup on 32 cores, we'd be nowhere close.
Additionally, the "plaintext" benchmark doesn't touch the DB at all. I
tried commenting out all of the DB code entirely, and it did not
change the results.

My guess is that the web server is just doing a lot of per-response
work that would need to be optimized.

Sam


Possibly ... I admit that I did not look at the plain text results: I 
was drawn to the fact that the DB results impose a lot of non-Racket 
overhead.


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/cfc6c027-180d-d822-6d36-9f1cfb1849fc%40comcast.net.


Re: [racket-users] Re: [racket] Web Framework Benchmarks

2020-06-01 Thread George Neuner



On 6/1/2020 1:40 PM, Bogdan Popa wrote:

I replied earlier today off of my Phone, but, for whatever reason
(caught in the moderation queue?), it's not showing up in this thread.

Here's what it said:

The reason for poor performance relative to the other
langs/frameworks is that there is currently no easy way to take
advantage of multiple cores using the web framework so that's being
benchmarked is single-core performance.

This is mainly a problem for benchmarks such as this, but not really
an issue in the real world where you'd just run multiple processes
with a load balancer in front.


Single core [by itself] doesn't explain the enormous performance 
difference between Racket and Django.


I haven't looked at the Django submission - Python's (in)comprehensions 
give me a headache.  But Python's DB pool is threaded, and Python's 
threads are core limited by the GIL in all the major implementations 
(excepting Jython).


There are a few things Python can do faster than Racket, but the VAST 
difference in performance shown in the techempower tests isn't explained 
by them.  My suspicion is that the Racket application is making too many 
database connections and not relying enough on its open connection 
pool.  Hundreds of trivial requests can be served in the time it takes 
to spin up a new backend process.


YMMV,
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/9236dcff-81df-1db8-c2ef-06b20e4690ec%40comcast.net.


Re: [racket-users] Re: [racket] Web Framework Benchmarks

2020-06-01 Thread George Neuner



On 6/1/2020 11:12 AM, Sam Tobin-Hochstadt wrote:

I think the biggest thing is that no one has looked at optimizing
these benchmarks in Racket. If you tried out running one of these
benchmarks and ran the profiler it would probably show something
interesting.

Sam
The code[1] itself isn't bad.  There are a couple of minor things I 
personally would tweak, but in my opinion the main problem is with the 
database access.


Postgresql uses process parallelism - it forks a new backend process to 
handle each connection.  Assuming (???) there are enough concurrent 
requests to open the maximum number of DB pool connections, then 1024 is 
WAY too many.  PG experts recommend no more than 5..10 backend processes 
per core, but according to the environment details[2], the test machines 
have only 14 HT cores (28 threads).


Mind you I'm only guessing, but it looks to me like this application 
could be losing an enormous amount of time in the starting of new 
backend database processes.  And since it is running inside a Docker 
container, there also is some per connection overhead there.


The requests made by the tests[3] are so trivial (needing little 
additional Racket processing) that I would consider reducing the number 
of PG pool connections to just a few per core and see how that goes.  My 
expectation is that the time saved by spinning up many fewer PG 
processes will vastly outweigh any loss in absolute request 
concurrency.  [Particularly if they also are running PG itself inside 
Docker.]


YMMV,
George

[1] 
https://github.com/TechEmpower/FrameworkBenchmarks/blob/master/frameworks/Racket/racket/servlet.rkt
[2] 
https://www.techempower.com/benchmarks/#section=environment=ph=fortune
[3] 
https://github.com/TechEmpower/FrameworkBenchmarks/wiki/Project-Information-Framework-Tests-Overview


--
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/eafb41e8-734c-7666-e684-edade3731e79%40comcast.net.


Re: [racket-users] Function that potentially can return more than one value

2020-05-27 Thread George Neuner



On 5/27/2020 1:50 PM, Jens Axel Søgaard wrote:
Den ons. 27. maj 2020 kl. 19.27 skrev George Neuner 
mailto:gneun...@comcast.net>>:



On 5/27/2020 6:34 AM, Jens Axel Søgaard wrote:
>
> In standard Racket an application doesn't communicate how many
values
> a function is expected to produce.

You can ask:  see procedure-result-arity
https://docs.racket-lang.org/reference/procedures.html


I think  procedure-result-arity  answers the question "how many
values could this procedure return?" and not "how many values
is the procedure expected to return in this context?".


Oh, I get it ... it's not that you "don't know" what's expected, it's 
that you've got something that returns N values on some path and M 
values on some other path, etc.  and you can't predict which path will 
be followed.


Yeah, that is a problem:  e.g., I don't think procedure-result-arity  
works for  case-lambda  where different invocations can return different 
numbers of results.


In that case, better to return a container: a list, vector, hash, etc. 
rather than a bunch of individual values.  Or, if the function is canned 
[e..g, in a library] to put them into a container for your code to work 
with.



> I have written a small proof-of-concept of an assignment operator :=
> that communicates to a function how many extra values it is expected
> to produce (and still works with standard functions).
>
> Are there alternative solutions that are better than the "use a
> keyword" approach?

You can use  call-with-values  which connects the function that
produces
with the one that consumes, but they have to agree on the number of
values being passed or it won't work.


My problem is that the producer still needs to be told how many values 
to produce.



Sorry, I missed that - I thought you needed to know how many were 
produced by something.


The only way to call attention - particularly compiler attention - to a 
particular argument is to make it a keyword with no default value.


If your function has default behavior that the keyword(s) would only 
modify, then you can make keyword(s) optional using default values or by 
defining the function with  make-keyword-procedure.



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/5bea165b-3357-7236-173c-934ca3a0ab58%40comcast.net.


  1   2   3   4   5   6   >