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

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

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

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

#lang racket

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

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

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


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


>
> The closest I could find in the documentation was the #:auto property,
> but:
>
>1. it makes the field mutable, even though I'm not interested in
>mutating z
>2. the default value is fixed across all constructions, while I want z
>to depend on x and y
>
> Of course, I could make z an explicit field, write a custom constructor,
> and export that instead of the default constructor for foo. But that seems
> to be a Royal Pain, especially since (AFAIK) you can't provide the struct
> as a whole anymore. (And I need to write about 12 of these structs to boot.)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/9f9e1548-d01d-469f-b565-22601e02dd82n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAE8gKofa5xPzBP%3DZpd0UjtBUdj7hHArPGtqKKxkUfz1g%3DSbaxQ%40mail.gmail.com.


[racket-users] Re: Racket v8.1

2021-06-07 Thread Greg Davidson
How can I run Racket 8.1 on Android?  I'd love to run DrRacket natively 
and/or run raco under Termux.  Where can I find out more information?  
Thanks, _Greg

On Wednesday, May 5, 2021 at 9:39:22 AM UTC-7 johnbclements wrote:

> --
> Racket version 8.1 is now available from
>
> https://racket-lang.org/
>
>
> - DrRacket tabs can be dragged, and have new close buttons.
>
> - Racket CS supports cross-compilation using `raco exe`.
>
> - Racket CS supports Android on 32-bit and 64-bit ARM processors.
>
> - The database library supports running queries in OS threads.
>
> - Check-Syntax arrows correctly identify the definition site of
> identifiers with contracts.
>
> - Racket CS performance has improved for structure predicates and
> accessors
>
> - Racket CS is faster at multiplying extremely large numbers and
> dividing large integers.
>
> - Racket CS allows callbacks to raise exceptions if they are annotated
> with `#:callback-exns?`.
>
> - New ephemeron hash tables simplify the implementation of tables where
> keys can refer to values.
>
> - Typed Racket supports for/foldr.
>
> - The stepper works for #lang htdp/*sl.
>
> - Struct signatures work for the ASL teaching language.
>
> The following people contributed to this release:
>
> Alex Harsányi, Alex Knauth, Alexander Shopov, Alexis King, Andrew
> Mauer-Oats, Anish Athalye, Ben Greenman, Bert De Ketelaere, Bob Burger,
> Bogdan Popa, Brian Adkins, Cameron Moy, David Van Horn, Dexter Lagan,
> Dominik Pantůček, Fred Fu, Greg Hendershott, Gustavo Massaccesi, Hazel
> Levine, Ismael Luceno, Jack Firth, Jarhmander, John Clements, Jörgen
> Brandt, Laurent Orseau, Lazerbeak12345, Matthew Flatt, Matthias
> Felleisen, Micah Cantor, Mike Sperber, Noah Ma, Patrick McCarty, Paulo
> Matos, Pavel Panchekha, Philip McGrath, Philippe Meunier, R. Kent
> Dybvig, Robby Findler, Ryan Culpepper, Ryan Kramer, Sam Tobin-Hochstadt,
> Sergiu Ivanov, Shu-Hung You, Sorawee Porncharoenwase, Stephen De
> Gabrielle, William J. Bowman, bmitc, xxyzz, yjqww6, and ymdarake
>
> Feedback Welcome
> --
>
>

-- 
You received this message because you are subscribed to the Google 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/a2ef1984-7237-4075-be67-219b9577685an%40googlegroups.com.


Re: [racket-users] Can a new user defined pkg encompass nothing more than references to previously defined pkgs?

2021-06-07 Thread Philip McGrath
On Mon, Jun 7, 2021 at 1:46 PM Don Green  wrote:

> Following from Philip's 3rd point, which I think is very relevant, I
> surmise that I really should:
> 1) build libraries ;that reference my code (These libraries are built
> within a user-defined package.)
>

This seems right, though I would say that the libraries will be your code.


> 2) Then my initial question, refined, becomes:
> Can a new user defined library encompass nothing more than references to
> previous user defined libraries? (I think the answer is: yes).
>

Yes.


> 3) Since the library is said to be referenced through their
> collection-based paths this leads me to wonder:
> Am I expected to create my own pathed-collection that gives my code
> independence from the default installled racket pathed-collections?
>
> Then am I to use: (current-library-collection-links paths) to link my
> collection into the racket system?
>

It is exceedingly unlikely that using `current-library-collection-links` is
what you want. I would go so far as to say that you should not need to use
any feature relating to collection links in normal use of Racket: those
features are really for tinkering under the hood with new ways of building
and installing Racket.

I'm going to try to offer some concrete advice, with a lot of
assumptions—they may be wrong, but perhaps laying them out will highlight
anything I've missed. Given that you've mentioned the path
"/home/don/.plt-scheme/4.2.1/collects", it sounds like you have some code
that predates Racket's package system. The right thing to do is to turn
that code into a package and install it. (Note that, in Racket, making
something a package doesn't mean publishing it. It may exist only as a
directory on your local file system.)

Let's assume you have your code in paths like
"/home/don/.plt-scheme/4.2.1/collects/tic-tac-toe" and
"/home/don/.plt-scheme/4.2.1/collects/tetris". Make a new directory
"/home/don/my-first-racket-package" and copy your code from
"/home/don/.plt-scheme/4.2.1/collects" there. Create a file
"/home/don/my-first-racket-package/info.rkt" with contents like this:


#lang info

(define pkg-name "my-first-racket-package")
(define collection 'multi)
(define pkg-desc "My first Racket package")
(define version "0.0")
(define pkg-authors '(don))

(define deps
  '("base"))

(define build-deps
  '())


At this point, you should have a directory structure like this:

   - /home/don/my-first-racket-package/
  - info.rkt
  - tetris/
 - … various files and directories …
 - tic-tac-toe/
 - … various files and directories …

An important caveat: for simplicity, I've assumed your code in
"/home/don/.plt-scheme/4.2.1/collects" is not intermingled with the default
collections of minimal Racket. If they are mixed up, copy only your files.
(Corresponding collection directories will effectively be merged.)

Then, install your new package. You should not need to set any environment
variables or change anything in "config.rktd": indeed, it would be best if
you do not. You may want to uninstall and replace your system Racket
installation to get a clean configuration. To install the package, run:

cd /home/don/my-first-racket-package/ && raco pkg install

If your code uses functionality outside of minimal Racket, you may get a
warning about missing dependencies. Running:

raco setup --fix-pkg-deps my-first-racket-package

will attempt to add the necessary declarations to your "info.rkt" file.

In the future, you can run:

raco setup my-first-racket-package

to recompile all the code in your package. You can run these `raco setup`
commands regardless of your current working directory.

I hope this helps!

-Philip

-- 
You received this message because you are subscribed to the Google 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/01000179e7db69dd-946513ef-9a47-437b-88eb-6655396b83ac-00%40email.amazonses.com.


[racket-users] Should minimal Racket include "base"?

2021-06-07 Thread Philip McGrath
There seems to be an inconsistency about whether "minimal Racket" 
includes the "base" package. The downloads for Mac OS and Windows seem 
to include it, but both the Linux downloads and the source tarballs have 
only "racket-lib".


I know that Mac OS, Windows, and "natipkg" use the "racket-lib" package 
to pull in platform-specific dependencies, but this discrepancy seems 
unrelated to that difference.



-Philip

--
You received this message because you are subscribed to the Google 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/3bcf82a0-8f9e-c822-0f34-a0bd30b8657d%40philipmcgrath.com.


Re: [racket-users] Can a new user defined pkg encompass nothing more than references to previously defined pkgs?

2021-06-07 Thread Don Green
Following from Philip's 3rd point, which I think is very relevant, I 
surmise that I really should:
1) build libraries ;that reference my code (These libraries are built 
within a user-defined package.)
2) Then my initial question, refined, becomes:
Can a new user defined library encompass nothing more than references to 
previous user defined libraries? (I think the answer is: yes).
3) Since the library is said to be referenced through their 
collection-based paths this leads me to wonder:
Am I expected to create my own pathed-collection that gives my code 
independence from the default installled racket pathed-collections?

Then am I to use: (current-library-collection-links paths) to link my 
collection into the racket system?

I would then expect (current-library-collection-paths) to return the 2 
default racket v. 8.1 collection-paths, and my own collection-path.

On Sunday, June 6, 2021 at 7:23:15 PM UTC-6 Philip McGrath wrote:

> On Sun, Jun 6, 2021 at 7:59 PM Ben Greenman  wrote:
>
>> On 6/6/21, Don Green  wrote:
>> >
>> > Can a new user defined pkg encompass nothing more than references to
>> > previously defined pkgs so that every  user created module references a
>> > single user defined pkg?
>>
>> Yes. You can make a new package whose main.rkt provides lots of
>> identifiers from other packages.
>
>
> I can see at least three different interpretations of the question. In an 
> attempt to clear up any possible misunderstandings, let me try to pull them 
> apart:
>
>1. Ben's answer is correct if the question really meant, "so that 
>every user created module references a single user defined" *module*. 
>The omnibus module (`#lang reprovide` is a good choice) may be in the same 
>package as other user-defined modules that use it, or additional packages 
>may depend on the package containing the omnibus module.
>2. If the question instead meant, "so that every user created" 
>*package* "references a single user defined pkg", the answer is also 
>yes, but in a different way. A good example of this would be the 
>"typed-racket" package, which combines the packages "typed-racket-lib" and 
>"typed-racket-doc". The "typed-racket" consists simply of an "info.rkt" 
>file with appropriate definitions for `deps` and `implies`.
>3. On the other hand, if the question literally meant, "so that every 
>user created module references a single user defined pkg", then the 
> answer, 
>strictly speaking, is no, because modules can not refer to packages per se.
>
> The third possibility is where I see the most potential for 
> misunderstanding. From Package Management in Racket", § 1.1 "What is a 
> Package?" <
> https://docs.racket-lang.org/pkg/getting-started.html#%28part._.What_is_a_.Package_%29
> >:
>
>> A package 
>>  
>> is not something that you refer to directly in your Racket programs. 
>> Instead, a package 
>>  
>> is a set of libraries that fit into the collection 
>> 
>>  
>> hierarchy, and you refer to libraries through their collection 
>> -based
>>  
>> paths. Libraries that are close in the hierarchy may be provided by 
>> different packages, while a single package may provide libraries that are 
>> far from each other in the hierarchy (but that are conceptually related, 
>> somehow).
>>
>> Racket documentation tells you which package provides a given library. 
>> For example, the documentation for the pict/face 
>> 
>>  
>> library says that it is provided by the pict-lib package.If you’re 
>> reading this in a web browser, click pict/face 
>> 
>>  
>> to go straight to its documentation.
>>
>> Over time, packages may be refactored so that a library moves to a 
>> different package, but the original package should continue to provide the 
>> library, too, by declaring a dependency on the new package. More generally, 
>> a package is intended to have an interface that only grows in terms of 
>> libraries, bindings, and functionality, which provides a basic level of 
>> backward compatibility. Incompatible changes should be implemented in a new 
>> package.
>>
>
> -Philip
>
>

-- 
You received this message because you are subscribed to the Google 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/02264bb7-27c0-4f79-9ad4-75626c3b4b7an%40googlegroups.com.


Re: [racket-users] Could Racket be used as a "frontend" for a non-Racket language?

2021-06-07 Thread Stephen Foster
This is one of the main ways I use Racket -- but as a front-end for 
JavaScript, not C#.

On Sunday, June 6, 2021 at 9:47:38 PM UTC-7 Philip McGrath wrote:

> I haven't done much with this personally, but a few pointers in Racket:
>
>- Urlang uses Racket's macro system as a front-end for JavaScript (in 
>the way you discuss with C#, not compiling Racket to JavaScript): 
>https://github.com/soegaard/urlang
>- Alexis King's Hackett is an experimental Haskell-like `#lang`: 
>https://lexi-lambda.github.io/hackett/ While it currently only runs on 
>the Racket runtime system, Alexis' blog post, "Reimplementing Hackett’s 
>type language: expanding to custom core forms in Racket", discusses the 
>possibility of an alternate backend targeting GHC and goes into extremely 
>useful detail about implementation techniques that can help: 
>
> https://lexi-lambda.github.io/blog/2018/04/15/reimplementing-hackett-s-type-language-expanding-to-custom-core-forms-in-racket/
>- The recent paper "Macros for Domain-Specific Languages" (
>https://dl.acm.org/doi/pdf/10.1145/3428297) presents a high-level API 
>for doing many of the things the aforementioned blog post implements by 
>hand. (Alexis is a co-author on the paper.)  The `ee-lib` library provides 
>the API discussed in the paper: 
>https://docs.racket-lang.org/ee-lib/index.html (I have done the 
>by-hand approach to custom core forms, and I'm excited to try the new 
>library.)
>
> -Philip
>
>
> On Sun, Jun 6, 2021 at 11:35 PM Robert Calco  wrote:
>
>> Check out IronScheme ... it 
>> may be just what you're looking for.
>>
>> - Bob
>>
>> On Sun, Jun 6, 2021 at 10:02 PM Ryan Kramer  wrote:
>>
>>> I have no plans to work on this, but I am curious if this has been 
>>> discussed or attempted...
>>>
>>> Motivation: My job has been C# for many years and while C# is very 
>>> appropriate for most of the problems I encounter at work, sometimes a 
>>> problem comes along that makes me want more power. In those situations, I 
>>> think the language I want is "C# except now it's S-expressions and it has 
>>> Racket's macro system."
>>>
>>> And then I wonder if an alternate version of C# could be implemented 
>>> this way:
>>> 1) Create a new grammar for what a fully-expanded C# AST is. This will 
>>> be in terms of Racket syntax objects, just like Racket's definition of a 
>>> Fully Expanded Program.
>>> 2) Write a compiler that generates CIL (the bytecode) given a 
>>> fully-expanded C# AST.
>>> 3) Use Racket's #lang mechanism and macro system to implement the 
>>> surface language.
>>>
>>> Now this new C# could borrow a lot of power from Racket, right? For 
>>> example, I could make all of Racket available during expansion! Even if I 
>>> don't want C#-the-surface-language to have macros at all, why shouldn't I 
>>> keep the Racket-powered backdoor open? As long as you generate a valid C# 
>>> AST, I should be able to compile it for you.
>>>
>>> The #lang mechanism and Scribble are two other nice things that could 
>>> probably be adapted into the new C# if desired.
>>>
>>> I can understand why Microsoft wouldn't do this. But I've seen enough 
>>> hobby languages, and I'm surprised that none of them do this. Reusing a 
>>> backend (like dotnet or the JVM) is common, reusing a "frontend" is 
>>> something I've never seen. Is Racket's macro system too specific to 
>>> Racket's definition of a fully-expanded program? (The little bit I've done 
>>> with local-expand and stop-ids makes me think it would work fine.) Is there 
>>> something else that would make this approach more trouble than it's worth?
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Racket Users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to racket-users...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/racket-users/cc7c1792-ba59-400f-856a-3bb02a6096fbn%40googlegroups.com
>>>  
>>> 
>>> .
>>>
>>
>>
>> -- 
>> *Bob Calco*
>>
>> bobc...@gmail.com
>> 813-997-3583 <(813)%20997-3583> (work mobile)
>> 813-523-3751 <(813)%20523-3751> (personal mobile)
>>
>> *"But you can catch yourself entertaining habitually certain ideas and 
>> setting others aside; and this, I think, is where our personal destinies 
>> are largely decided." *-- *Alfred North Whitehead*
>>
>> *"And now I see with eye serene the very pulse of the machine." *--* William 
>> Wordsworth*
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users...@googlegroups.com.
>>
> To view this discussion on the 

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

2021-06-07 Thread Arthur Nunes-Harwitt

Hi,

  Marc Feeley has done some work on embedded scheme.  Here are a couple of 
links:


http://www.iro.umontreal.ca/~feeley/papers/StAmourBouchardFeeleySW08.pdf

http://www.iro.umontreal.ca/~feeley/papers/DubeFeeleyHOSC05.pdf

==
Arthur Nunes-Harwitt
Computer Science Department, Rochester Institute of Technology
Room GOL-3509
585-475-4916
==

"I don't know what the language of the future will be
called, but it will look like LISP."

This email is confidential and intended for the named recipient(s). In
the event the email is received by someone other than the recipient,
please notify the sender at a...@cs.rit.edu.

On Sat, 5 Jun 2021, 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.

--
You received this message because you are subscribed to the Google 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/da72cdd0-2143-4610-9e4d-f987931c9314n%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/alpine.DEB.2.21.2106070918490.22607%40heracles.