Re: [racket-users] Experiences with Racket on RISC-V?

2019-01-07 Thread 'Paulo Matos' via Racket Users



On 07/01/2019 22:38, Andrei Formiga wrote:
> Sorry to slightly hijack the thread here, but what would be a good
> RISC-V dev board to experiment with Racket on it? 

I have the HiFive Unleashed which I recommend:
https://www.sifive.com/boards/hifive-unleashed

-- 
Paulo Matos

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] triggering servlet on GET parameters

2019-01-07 Thread Jesse Alama

On 7 Jan 2019, at 0:16, Matthew Butterick wrote:

Don't know if it would be an instructive example, but the Pollen 
project server [1], though not intended for production use, is a 
self-contained HTTP server that handles dynamic generation of HTML (it 
even works with Scribble files), which sounds similar to what you're 
trying to do.


Jesse Alama's book Server: Racket [2] is an excellent resource. Among 
many other things, I learned that you can invent arbitrary HTTP 
methods beyond GET and POST, thereby avoiding encoding conventions 
like "?action=edit". Instead, you can just have an HTTP method called 
EDIT.


In Stephen's case, I think the classical HTTP method PUT is a good 
match. PUT is intended to mean, roughly (precise definition at [1]): 
here, take this request body; *it* will be the content in response 
bodies to GET requests for this URL from now on.


One of my favorite examples of custom (non-canonical) HTTP methods is 
for "cancelling" something (an order, an edit, some item of some group).


  CANCEL https://example.com/order/4567

I find this method-URL pair more palatable than something like

  POST https://example.com/cancel/order/4567

where the action (cancelling) is part of the URL.

Alas, not all browsers support such HTTP methods (such requests may get 
silently converted into POSTs, despite your wishes), so they tend to be 
relevant only in scenarios where you're using programmable HTTP clients 
(e.g., command line tools such as cURL or Httpie [2], or libraries such 
as Greg Hendershott's http [3]).


Jesse

[1] https://tools.ietf.org/html/rfc2616#section-9.6

[2] https://httpie.org

[3] https://pkgs.racket-lang.org/package/http

--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Functional augmenting

2019-01-07 Thread Neil Van Dyke

David Thrane Christiansen wrote on 1/7/19 6:02 PM:

A quick grep of the source makes it look like there's at least some support for 
these. But the docs are certainly less easy to navigate than Scribble docs!


The developer of Swindle, Eli Barzilay, was one of the developers of 
Scribble, as well. :)


For now, I think you have to work from various documents and files at: 
http://barzilay.org/Swindle/


(Swindle goes back to early PLT/Racket days, when you were lucky if you 
got a "README" file, much less a "doc.txt".  You can tell from that Web 
page that a lot of work went into idiomatic polish for DrScheme at the 
time.  Once there were package systems and richer documentation formats 
and other tools, I imagine there's only so much expert time and funding 
to go around, for so much work to be done.  Eli is one of the prominent 
contributors to PLT/Racket who unfortunately I haven't seen on the list 
in a while.)


--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Functional augmenting

2019-01-07 Thread Neil Van Dyke

George Neuner wrote on 1/7/19 4:49 PM:

Though I mostly agree with you, your "advice" does have its uses:

http://www.gigamonkeys.com/book/object-reorientation-generic-functions.html
    in particular see the sections on method combinations.


Thank you; I should've looked it up before incorrectly assuming that you 
were talking about "advice" from some Lisps.  I initially thought the 
original question was getting at something like `defadvice`:


https://franz.com/support/documentation/10.1/doc/operators/excl/defadvice.htm
https://www.gnu.org/software/emacs/manual/html_node/elisp/Porting-old-advice.html

Part of what bugs me is violation of expectations:  In Racket, when I 
see or use a procedure reference in some code, I expect to get a 
particular procedure implementation.  (Given a straightforward 
understanding of `#lang`, `require`, scoping, and syntax extension.)  If 
that's instead documented to be a generic, then my expectations change 
to the implementation I receive (probably) performing an analogous 
operation.  (Actually, in Racket, I'd say generics and classes are 
usually used only when overriding is definitely happening.)


--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Matching against alpha-equivalence classes in Redex?

2019-01-07 Thread Robby Findler
The true expert on this is, of course, Paul (now cc'd) but I think
that the short answer is that you cannot have two different binding
occurrences that are the same variable. That's just not how things
work. :(

In this case, I think you can probably just substitute in for the
variable, tho, in that rule and get what you want. That is, let the
lambda and the Pi have different binders, but replace one with the
others after you free all the occurrences (by opening up the term).

That said, there may be other ways to approach this (hence the Paul mention...)

hth,
Robby

On Mon, Jan 7, 2019 at 5:47 PM Joey Eremondi  wrote:
>
> I'm modelling dependent types in redex, and I've got a rule that looks like 
> this:
>
>  [
>   (WellFormed (EnvExt x gU Gamma))
>   (Check (EnvExt x gU Gamma) gu gV)
>   --- 
> "CheckLamPi"
>   (Check Gamma  (CanonicalLam x gu)  (CanonicalPi x gU gV))]
>
> CanonicalLam and CanonicalPi each bind x inside gu and gV respectively.
>
> The problem is, elsewhere in my model I have a type normalization judgment, 
> and when it normalizes the CanonicalPi type,
> it binds a fresh variable, not the original variable that was given.
> This causes the "CheckLamPi" rule to never be called in typechecking, since 
> it no longer
>
> What I really want is to treat terms as alpha equivalence classes, i.e. to 
> write something like the above, and have it implicitly be implemented as 
> something like this:
>
> [
>   (fresh z)
>   (WellFormed (EnvExt z gU Gamma))
>   (Check (EnvExt x gU Gamma) (subst z x gu) (subst z y gV) )
>   --- 
> "CheckLamPi"
>   (Check Gamma  (CanonicalLam x gu)  (CanonicalPi y gU gV))]
>
>
> That is, I want the pattern matching not to check if the term and type bind 
> literally the same variable, but to alpha-rename them to something that binds 
> the same name.
>
> Do I have to write a rule that explicitly does this substitution? Or is there 
> a way to tell Redex that I mean the second form when I write the first?
>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Matching against alpha-equivalence classes in Redex?

2019-01-07 Thread Joey Eremondi
I'm modelling dependent types in redex, and I've got a rule that looks like 
this:

 [
  (WellFormed (EnvExt x gU Gamma))
  (Check (EnvExt x gU Gamma) gu gV)
  --- 
"CheckLamPi"
  (Check Gamma  (CanonicalLam x gu)  (CanonicalPi x gU gV))]

CanonicalLam and CanonicalPi each bind x inside gu and gV respectively.

The problem is, elsewhere in my model I have a type normalization judgment, 
and when it normalizes the CanonicalPi type,
it binds a fresh variable, not the original variable that was given.
This causes the "CheckLamPi" rule to never be called in typechecking, since 
it no longer 

What I really want is to treat terms as alpha equivalence classes, i.e. to 
write something like the above, and have it implicitly be implemented as 
something like this:

[
  (fresh z)
  (WellFormed (EnvExt z gU Gamma))
  (Check (EnvExt x gU Gamma) (subst z x gu) (subst z y gV) )
  --- 
"CheckLamPi"
  (Check Gamma  (CanonicalLam x gu)  (CanonicalPi y gU gV))]


That is, I want the pattern matching not to check if the term and type bind 
literally the same variable, but to alpha-rename them to something that 
binds the same name.

Do I have to write a rule that explicitly does this substitution? Or is 
there a way to tell Redex that I mean the second form when I write the 
first?

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Functional augmenting

2019-01-07 Thread David Thrane Christiansen
> Swindle/CLOS does implement generic functions, but I'm not aware that it
> also implements the before / after / around methods that we have been
> talking about.  But then, it does so much I may just have missed
> something ... its documentation can be tough to read at times.

A quick grep of the source makes it look like there's at least some
support for these. But the docs are certainly less easy to navigate
than Scribble docs!

David

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Functional augmenting

2019-01-07 Thread George Neuner



On 1/7/2019 5:32 PM, David Thrane Christiansen wrote:

> The basic generics machinery isn't terribly hard to implement inside a
> compiler.  I'm not sure though how I would do it on top of Racket.   I'm
> sure I could hack up some ugly macros that would work, but it seems like
> it needs to be a language to be done right.

What about Swindle?

https://docs.racket-lang.org/swindle/index.html

David


Swindle/CLOS does implement generic functions, but I'm not aware that it 
also implements the before / after / around methods that we have been 
talking about.  But then, it does so much I may just have missed 
something ... its documentation can be tough to read at times.


Thanks for reminding me about 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.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Functional augmenting

2019-01-07 Thread David Thrane Christiansen
> The basic generics machinery isn't terribly hard to implement inside a
> compiler.  I'm not sure though how I would do it on top of Racket.   I'm
> sure I could hack up some ugly macros that would work, but it seems like
> it needs to be a language to be done right.

What about Swindle?

https://docs.racket-lang.org/swindle/index.html

David

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Experiences with Racket on RISC-V?

2019-01-07 Thread Neil Van Dyke
These are pretty new, and the prices are higher than other ISAs with 
economies-of-scale and mostly long-amortized development costs (and 
there's perhaps no loss-leaders or dumping for market share or lock-in, 
like we sometimes see in industry).


The HiFive1 is more like a $60 Arduino or maybe RasPi:
https://www.sifive.com/boards/hifive1

The HiFive Unleashed, when combined with their Expansion Board, could be 
used to make a workstation, but is pretty new, and costs thousands of 
dollars:

https://www.sifive.com/boards/hifive-unleashed

I've seen "RISC-V" USB dongle-like boards, but the ones I've seen are 
just little FPGA experimenter boards burnt with RISC-V logic.


That's what I found, last time I looked.  Paulo or others might know 
other boards.


There's also always emulators, and RISC-V logic you program yourself on 
bigger general-purpose FPGA boards.  (Programming FPGA yourself means 
you're one small enhancement away from being able to call yourself a CPU 
designer.  :)  If you do FPGA, it would help to try to use an open 
toolchain, but I think the options for that are still relatively early 
and improving.  (Last I looked, the open toolchains would let you use 
only a few small FPGAs, but I saw something the other day that suggests 
the environment is improving, so look for the latest info/news, whenever 
you start.)


--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Functional augmenting

2019-01-07 Thread George Neuner




On 1/7/2019 2:23 PM, Neil Van Dyke wrote:

George Neuner wrote on 1/7/19 1:12 PM:
Your examples look a lot like what is possible using Lisp's generic 
functions: specifically "before", "after" and "around" functions.


Before/after/around are what I call "advice".  Advice is a lifesaver 
when you need it and there's no good documented interface.  For 
example: "I really-really-really need that one function in that 
library I use to work differently, but I'm not allowed to modify that 
library, and I plan to quit this job before anyone else sees my code 
or tries to update to a new version of that library".  But I don't 
think of advice as good for documented and maintainable code for 
software engineering.


13 of one, baker's dozen of the other. 

Though I mostly agree with you, your "advice" does have its uses:

http://www.gigamonkeys.com/book/object-reorientation-generic-functions.html
    in particular see the sections on method combinations.

And this is the "documentation" for generic functions in Lisp:

http://www.lispworks.com/documentation/HyperSpec/Body/m_defgen.htm#defgeneric
http://www.lispworks.com/documentation/HyperSpec/Body/m_defmet.htm#defmethod


The basic generics machinery isn't terribly hard to implement inside a 
compiler.  I'm not sure though how I would do it on top of Racket.   I'm 
sure I could hack up some ugly macros that would work, but it seems like 
it needs to be a language to be done right.


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.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Experiences with Racket on RISC-V?

2019-01-07 Thread Andrei Formiga
Sorry to slightly hijack the thread here, but what would be a good RISC-V
dev board to experiment with Racket on it?

On Mon, Jan 7, 2019 at 3:19 PM David Thrane Christiansen <
da...@davidchristiansen.dk> wrote:

> Den man. 7. jan. 2019 kl. 01.45 skrev Paulo Matos :
> > I don't really understand the risky bet comment. What's a risky bet? To
> > use Racket on RISC-V for production? Well, yes, it doesn't run yet.
> > RacketCS doesn't compile because the RISC-V backend for Chez is not
> > finished, Racket doesn't compile because libffi, at least, hasn't been
> > ported to RISC-V.
>
> The presence of a Debian package had made me think that Racket indeed
> compiled and ran on that architecture - I suppose I must have
> misunderstood.
>
> "Production" means very different things for different contexts, and
> I'm in one where it would be fine to have something that was a bit
> experimental but not where I can write a thing on my laptop and then
> find out that I can't run it at all when it comes time to use it on a
> RISC-V box in a few weeks. Thanks for helping me understand the
> current state of things!
>
> > However, it's not a risky bet to support the porting of Racket for
> > RISC-V because both are really mature projects which are here to stay
> > and lots can be done on RISC-V since the base ISA's and some extension
> > specs have been frozen.
>
> Totally agree - I think there's a bright future for RISC-V. I was just
> hoping to be able to write a little prototype in Racket and run it in
> a couple weeks, but it seems that I should probably wait a year or so
> before I start doing that, and write the little prototype in something
> else. Thanks for the info!
>
> Thanks again for taking the time.
>
> David
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>


-- 
[]s, Andrei Formiga

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Functional augmenting

2019-01-07 Thread Neil Van Dyke

George Neuner wrote on 1/7/19 1:12 PM:
Your examples look a lot like what is possible using Lisp's generic 
functions: specifically "before", "after" and "around" functions.


Before/after/around are what I call "advice".  Advice is a lifesaver 
when you need it and there's no good documented interface.  For example: 
"I really-really-really need that one function in that library I use to 
work differently, but I'm not allowed to modify that library, and I plan 
to quit this job before anyone else sees my code or tries to update to a 
new version of that library".  But I don't think of advice as good for 
documented and maintainable code for software engineering.


Perhaps half of programming language features and engineering processes 
is giving us non-advice ways to accomplish our goals. :)


(Now I'm bracing for a funny thing that sometimes happens.  If you 
mention something that can be done, but that you discourage, it gets in 
people's heads, and some people also read up and experiment with it, 
which gets it more into their heads, and, the next time people are 
solving a problem, and different solutions are popping into their 
heads... this can lead to the discouraged thing being done more than if 
you'd never mentioned it at all.  It's like if the language 
documentation for Racket discusses `eval` prominently, even with 
discouragement, and then `eval` is in new programmers' heads as a tool 
to use, before they really understand what are almost always better 
ways, like a baby velociraptor climbing over a litter of puppies, when 
what you ultimately need is a nice family dog.  Crud; I might've just 
done it again. :)


--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Debugging Judgements in Redex?

2019-01-07 Thread Joey Eremondi
Perfect, that did the trick, thanks!

On Wednesday, January 2, 2019 at 7:52:40 PM UTC-8, Robby Findler wrote:
>
> Did you try using `current-traced-metafunctions` ? It is poorly named, 
> I know. And, even worse, I see that the docs don't actually say that 
> it traces judgment forms too. 
>
> Robby 
>
> On Wed, Jan 2, 2019 at 9:18 PM Joey Eremondi  > wrote: 
> > 
> > I'm wondering, is there a way to show some sort of trace for a call to 
> judgment-holds that returns '() or #f? 
> > 
> > I'm in a situation where a judgment that I expect to hold does not, and 
> it's tricky to find out by hand where it is failing. The #mode requirement 
> for the judgments suggests an obvious algorithm for establishing whether a 
> judgment holds, which I assume is what judgment-holds uses. Is there any 
> way to see what steps it takes, and were it fails? 
> > 
> > -- 
> > You received this message because you are subscribed 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 . 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Experiences with Racket on RISC-V?

2019-01-07 Thread David Thrane Christiansen
Den man. 7. jan. 2019 kl. 01.45 skrev Paulo Matos :
> I don't really understand the risky bet comment. What's a risky bet? To
> use Racket on RISC-V for production? Well, yes, it doesn't run yet.
> RacketCS doesn't compile because the RISC-V backend for Chez is not
> finished, Racket doesn't compile because libffi, at least, hasn't been
> ported to RISC-V.

The presence of a Debian package had made me think that Racket indeed
compiled and ran on that architecture - I suppose I must have
misunderstood.

"Production" means very different things for different contexts, and
I'm in one where it would be fine to have something that was a bit
experimental but not where I can write a thing on my laptop and then
find out that I can't run it at all when it comes time to use it on a
RISC-V box in a few weeks. Thanks for helping me understand the
current state of things!

> However, it's not a risky bet to support the porting of Racket for
> RISC-V because both are really mature projects which are here to stay
> and lots can be done on RISC-V since the base ISA's and some extension
> specs have been frozen.

Totally agree - I think there's a bright future for RISC-V. I was just
hoping to be able to write a little prototype in Racket and run it in
a couple weeks, but it seems that I should probably wait a year or so
before I start doing that, and write the little prototype in something
else. Thanks for the info!

Thanks again for taking the time.

David

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Functional augmenting

2019-01-07 Thread David Storrs
On Mon, Jan 7, 2019 at 1:12 PM George Neuner  wrote:

> Hi David,
>
> On 1/7/2019 12:57 PM, David Storrs wrote:
>
> I haven't worked with Racket's generics before, but a quick skim through
> the documentation suggests that no, that's not it.  Racket generics appear
> to relate to collections and structs, whereas I was looking for something
> that operates on arbitrary functions.  Perhaps I've misunderstood something?
>
>
> I wasn't talking about Racket but about Common Lisp.  Your examples look a
> lot like what is possible using Lisp's generic functions: specifically
> "before", "after" and "around" functions.  I was asking if  Lisp was the
> source of your aspirations.
>

Ah.  No, it wasn't.  My aspirations were based on experience in Perl,
although Perl may have borrowed these constructs from CL.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Functional augmenting

2019-01-07 Thread George Neuner

Hi David,

On 1/7/2019 12:57 PM, David Storrs wrote:
I haven't worked with Racket's generics before, but a quick skim 
through the documentation suggests that no, that's not it.  Racket 
generics appear to relate to collections and structs, whereas I was 
looking for something that operates on arbitrary functions.  Perhaps 
I've misunderstood something?


I wasn't talking about Racket but about Common Lisp.  Your examples look 
a lot like what is possible using Lisp's generic functions: specifically 
"before", "after" and "around" functions.  I was asking if  Lisp was the 
source of your aspirations.


Unfortunately I don't know of any existing way to do that in Racket.  
[Obviously, someone could build the needed infrastructure.]


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.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Functional augmenting

2019-01-07 Thread David Storrs
On Sun, Jan 6, 2019 at 4:28 PM George Neuner  wrote:

> On Fri, 4 Jan 2019 13:30:43 -0500, David Storrs
>  wrote:
>
> >Racket's OO system has the 'augment' family of functionality that allows
> >you to change how a function works.  I'm wondering if there's a way to do
> >something similar in functional Racket.  For example, when I was working
> in
> >Perl I used to be able to do something like this Racket pseudocode:
> >
> >> (define (greet name)
> >  (println (string-append  "Hi, " name)))
> >
> >> (greet "bob")
> >"Hi, bob!"
> >
> > :
> >
> >> (before greet ~a)  ; argument to greet is now passed to ~a before greet
> >gets it
> >
> > :
> >
> >; or, alternatively, instead of pre, let's do:
> >> (after greet list)
> >
> > :
> >
> >; or, how about full control?
> >> (around greet
> >  (lambda (name)
> >(displayln "About to enter greet")
> >(inner (~a name))
> >(displayln "After greet"))>
>
>
> Not that I can help wrt Racket, but this looks a lot like generic
> functions in Lisp.  Is that what you're trying to achieve?
>

I haven't worked with Racket's generics before, but a quick skim through
the documentation suggests that no, that's not it.  Racket generics appear
to relate to collections and structs, whereas I was looking for something
that operates on arbitrary functions.  Perhaps I've misunderstood something?

Dave

>
>
> 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.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Functional augmenting

2019-01-07 Thread David Storrs
Thank you, Philip.  This is helpful.

On Fri, Jan 4, 2019 at 9:04 PM Philip McGrath 
wrote:

> I can't think of "something similar in functional Racket" (of course you
> can write purely functional programs with racket/class, but I know what you
> mean). I think it would be fairly easy to implement "something similar,"
> but I want to clarify what you have in mind, because augmentable methods
> don't quite match up with your pseudocode.
>
> The first point is that what you're doing seems more like "override" than
> "augment." Overriding methods is probably familiar to OOP people, but for
> illustration, here's a class that implements an overridable method:
> (define hi%
>   (class object%
> (super-new)
> (define/public (greet who)
>   (string-append  "Hi, " who
> When a subclass overrides the `greet` method, its implementation of the
> method gets called. The subclass can chose to call the superclass'
> implementation using `super`:
> (send (new (class hi%
>  (super-new)
>  (define/override (greet)
>(list (super greet "Alice")
>  (super greet "Bob")
>   greet)
> ;; -> '("Hi, Alice." "Hi, Bob.")
> Or, it can ignore the superclass's implementation altogether:
> (send (new (class hi%
>  (super-new)
>  (define/override (greet)
>"Leave me alone!")))
>   greet)
> ;; -> "Leave me alone!"
>
> In contrast, with an augmentable method, control start's with the
> superclass' implementation. The subclass only gets control if/when the
> superclass uses `inner` to invoke its implementation:
> (define librarian%
>   (class object%
> (super-new)
> (define/pubment (goodnight)
>   (format "Goodnight, ~a."
>   (or (with-handlers ([exn:fail? (λ (e) #f)])
> (inner #f goodnight))
>   "my someone")
>
> (send (new librarian%) goodnight)
> ;; -> "Goodnight, my someone."
> (send (new (class librarian%
>  (super-new)
>  (define/augment (goodnight)
>"my love")))
>   goodnight)
> ;; -> "Goodnight, my love."
> A subclass can't use `augment` to escape the superclass:
> (send (new (class librarian%
>  (super-new)
>  (define/augment (goodnight)
>(eprintf "We've got trouble!\n")
>(error "Leave River City"
>   goodnight)
> ;; prints "We've got trouble!\n" to stderr
> ;; -> "Goodnight, my someone."
>
> Aside from that, neither `augment` nor `override` change the
> implementation of a method for immediate instances of the superclass,
> whereas your `before`, `after`, and `around` effectively `set!` the
> identifier greet to a different value than it had before. With that
> insight, it isn't difficult to make your pseudocode run:
>
> #lang racket
>
> (require rackunit
>  syntax/parse/define
>  racket/stxparam
>  (for-syntax syntax/transformer))
>
> (define-simple-macro (before name:id proc:expr ...+)
>   (set! name (compose name proc ...)))
> (define-simple-macro (after name:id proc:expr ...+)
>   #:with name* #`(compose #,@(reverse (syntax->list #'(name proc ...
>   (set! name name*))
> (define-syntax-parameter inner
>   (λ (stx) (raise-syntax-error #f "only allowed inside of around" stx)))
> (define-simple-macro (around name:id proc:expr)
>   (set! name
> (let ([inner-name name])
>   (syntax-parameterize
>   ([inner (make-variable-like-transformer #'inner-name)])
> proc
>
> (define (greet name)
>   (string-append  "Hi, " name "!"))
>
> (check-equal? (greet "Bob") "Hi, Bob!")
> (check-exn #rx"string-append" (λ () (greet 'Bob)))
>
> (before greet ~a)
> (check-equal? (greet 'Bob) "Hi, Bob!")
>
> (after greet list)
> (check-equal? (greet "Bob") '("Hi, Bob!"))
>
> (around greet
> (λ (name)
>   (list "You asked me to say:"
> (inner name)
> "so I did.")))
>
> (check-equal? (greet 'Bob)
>   '("You asked me to say:"
> ("Hi, Bob!")
> "so I did."))
>
>
>
> -Philip
>
>
> On Fri, Jan 4, 2019 at 2:51 PM David Storrs 
> wrote:
>
>> Cool, thanks.  I'll look into generics more.  I've skimmed past them
>> before this but never really dug in.
>>
>> On Fri, Jan 4, 2019 at 1:46 PM Neil Van Dyke 
>> wrote:
>>
>>> I don't know what all is currently available for Racket[1], but two
>>> search keywords to slog through are "advice" and "aspect".
>>>
>>> Aspects and other framework-y interfaces can be good for extensibility
>>> of a system.  (But maybe try to make loosely-coupled reusable modules
>>> that don't need it, as much as practical.)  When you don't have an
>>> interface like that, but really-really need it, advice is sometimes a
>>> lifesaver.
>>>
>>> Separately, your particular example suggests that Racket's generics
>>> might do what you currently need to do.
>>>
>>>
>>> [1] It seems a lot of 

Re: [racket-users] triggering servlet on GET parameters

2019-01-07 Thread Jay McCarthy
You can use web-server/servlet and you don't need to use
web-server/dispatch if you don't want to. Your design seems good to
me.

On Sun, Jan 6, 2019 at 10:33 AM Stephen De Gabrielle
 wrote:
>
> Thank you Jay and David,
>
> Your suggestions were good, #:servlet-regexp #rx"" lets me capture the 
> request for a page and server the original file, or the edit servlet:
> http://localhost:8000/mouse.html
> http://localhost:8000/mouse.html?action=edit
>
> I've been reading a little more and I think I've made a mistake!  I'm using 
> 'Stateful Servlets'(require web-server/servlet), and I *think* I should be 
> using (require web-server/dispatch), so I can  capture the situation where a 
> static file is not found.
>
> Do you think web-server/dispatch is the right approach?
>
> My design is;
>
> GET http(s)://server/
> -> serve static file at specified path
> GET http(s)://server/?action=edit
> -> serve edit page servlet that retrieves scribble source
> GET http(s)://server/
> -> serve edit page adding parameters ?action=edit or maybe new
> POST http(s)://server/
> -> update scribble source file,  generate target html file in 
> #:server-root-path and redirect to target html file at 
> http(s)://server/
>
>
>
> On Thu, Jan 3, 2019 at 4:35 PM David Storrs  wrote:
>>
>> Stephen, you might also find this useful as a reference to crib from: 
>> http://matt.might.net/articles/low-level-web-in-racket/
>>
>> On Thu, Jan 3, 2019 at 11:10 AM Jay McCarthy  wrote:
>>>
>>> Use normal racket/base and web-server/servlet-env ‘s serve/servlet
>>>
>>> On Thu, Jan 3, 2019 at 10:53 AM David Storrs  wrote:



 On Wed, Jan 2, 2019 at 7:12 PM Jay McCarthy  wrote:
>
> You need to stop using `web-server/insta`


 What would you recommend he use instead of web-server/insta?

>
> so you can customize more.
> Then, you need to intercept ALL requests with your servlet. Then, your
> servlet just needs to call (next-dispatcher) and the static file
> handler will kick in, because it comes after servlets.
>
> Jay
>
> On Wed, Jan 2, 2019 at 7:08 PM Stephen De Gabrielle
>  wrote:
> >
> > Hi,
> >
> > I'm fooling around with #lang web-server/insta, and I can serve .html 
> > files by setting (static-files-path page-root), but I'd like to trigger 
> > my servlet if there is a '?action=edit' parameter set.
> >
> > e.g
> > https://localhost/start.html just serves the file (I can do this!)
> > https://localhost/start.html?action=edit  calls my servlet (I can't 
> > work out how to do this :( )
> >
> > (There is a lot of documentation but I'm a beginner with webdev so 
> > don't know where to look)
> >
> > Kind regards
> >
> > Stephen
> >
> > PS the project is a scribble based wiki. If you create a new page you 
> > enter raw scribble/manual in a form (my servlet) and it gets saved in a 
> > folder and transformed into html that is served directly by 
> > (static-files-path page-root), the conversion from raw scribble goes 
> > like this:
> > (require raco/all-tools)
> > (define raco-scribble-spec (hash-ref (all-tools) "scribble"))
> > ;;scribble-to-html : source target body
> > ;; generate html file from scribble file
> > (define (scribble-to-html source target) ;-> list of strings
> >   (parameterize ([current-command-line-arguments (vector "--html" 
> > source)]
> >  [current-directory target])
> > (dynamic-require (cadr raco-scribble-spec) #f)))
> >
> >
> > --
> > You received this message because you are subscribed to the Google 
> > Groups "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send 
> > an email to racket-users+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
> -=[ Jay McCarthy   http://jeapostrophe.github.io]=-
> -=[ Associate ProfessorPLT @ CS @ UMass Lowell ]=-
> -=[ Moses 1:33: And worlds without number have I created; ]=-
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>>>
>>> --
>>> -=[ Jay McCarthy   http://jeapostrophe.github.io]=-
>>> -=[ Associate ProfessorPLT @ CS @ UMass Lowell ]=-
>>> -=[ Moses 1:33: And worlds without number have I created; ]=-
>
> --
> 



-- 
-=[ Jay McCarthy   http://jeapostrophe.github.io]=-
-=[ Associate ProfessorPLT @ CS @ UMass Lowell ]=-
-=[ Moses 1:33: And worlds without number have I created; ]=-

-- 
You received this message because you 

Re: [racket-users] Does here any HtDP-y recipe for classic DP algorithm like backPack?

2019-01-07 Thread Matthias Felleisen


I would love to help, but I have only a faint clue as to what this message 
means: 

— please use a link that we can access 
— please send a runnable program
— what’s ps1
— what’s ps2 
— what’s OOM 

I am also not quite sure as for your motivation. HtDP is a book for beginners 
with design recipes that should eventually disappear into the tip of your 
fingers. While I do assign the knapsack problem in the context of Part V (both 
1e and 2e) to our students on occasion, I would consider this one of those 
problems where design recipes beyond a first course come into play. (Yes 
there’s a lot more to design recipes than HtDP explains. But at some point I 
needed to stop writing. :) 


As for the Python questions, I suggest you post that part to a Python mailing 
list. You will get more expert advice there than here. 

— Matthias




> On Jan 6, 2019, at 10:34 PM, piv det  wrote:
> 
> Here's the classic backpack 
> question(https://www.lintcode.com/problem/backpack/description):
> 
> Given n items with size Ai, an integer m denotes the size of a backpack. How 
> full you can fill this backpack?
> 
> Using classic DP with memoize to solve this problem in Racket would be ps1.
> 
> I would like to try to solve this problem in HtDP-y way, since lintcode 
> doesn't support Racket-lang, I use python to implement (refer: ps2).
> 
> lintcode told me that my python implementation is OOM, I was wondering if 
> maybe the `fn_for_n` and `fn_for_lon` is not the right hammer for this nail?
> 
> 
> 
> ps1 here ===
> #lang racket
> (require rackunit)
> 
> 
> (struct obj (value weight))
> (struct node (value weight paths))
> 
> (define (max-value objs max-weight)
>   (if (null? objs)
>   0
>   (match-let (((list-rest (struct obj (value weight)) rest) objs))
> (if (> weight max-weight)
> (max-value rest max-weight)
> (max (+ value (max-value rest (- max-weight weight)))
>  (max-value rest max-weight))
> 
> (define allcalls 0)
> (define memcalls 0)
> 
> (define (memoize f)
>   (let ((cache (make-hash)))
> (λ args
>   (set! allcalls (add1 allcalls))
>   (hash-ref! cache args
>  (thunk
>   (set! memcalls (add1 memcalls))
>   (apply f args))
> 
> (set! max-value (memoize max-value))
> 
> (define (max-value/nomem objs max-weight)
>   (if (null? objs)
>   0
>   (match-let (((list-rest (struct obj (value weight)) rest) objs))
> (if (> weight max-weight)
> (max-value/nomem rest max-weight)
> (max (+ value (max-value/nomem rest (- max-weight weight)))
>  (max-value/nomem rest max-weight))
> 
> ;; (o->node (obj 400 2))
> ;; ==> (node 400 2 (list (obj 400 2)))
> (define (o->node item)
>   (node (obj-value item) (obj-weight item) (list item)))
> 
> (define (n-eq=? n1 n2)
>   (and (= (node-value n1) (node-value n2))
>(= (node-weight n1) (node-weight n2
> 
> ;; lon: node list.'((node 200 7 ((obj 200 7))) (node 200 3 ((obj 200 3))) 
> (node 300 5 ((obj 300 5
> ;; W: weight
> ;; cur: node. (node 400 10 (list (obj 200 3) (obj 200 7)))
> ;; => list of node
> ;; (graph-nbs ex (node 200 3 (list (obj 200 3))) 10) =>
> ;; '((node 500 8 (list (obj 300 5) (obj 200 3
> (define (graph-nbs lon cur W)
> (let* ([head-cur (first (node-paths cur))] ; (obj 200 3)
>[rest-item (rest (member (o->node head-cur) lon n-eq=?))])
>   (filter (λ (ncur)
> (>= W (node-weight ncur)))
>   (map (λ (ncur) ;; ncur:(5 300 ((banana 5 300)))
>  (node (+ (node-value ncur) (node-value cur))
>(+ (node-weight ncur) (node-weight cur))
>(cons (first (node-paths ncur)) (node-paths cur
>rest-item
> 
> ;; loi: ITEM list defined as above. ex. (list (obj 200 7) (obj 200 3) (obj 
> 300 5))
> ;; W: weight
> ;; (ini-todo h1 10)
> ;; => (list (node 200 7 (list (obj 200 7)))
> ;;  (node 200 3 (list (obj 200 3)))
> ;;  (node 300 5 (list (obj 300 5
> (define (ini-todo loi W)
>   (map
>o->node
>(filter (λ (item)
>  (<= (obj-weight item) W))
>loi)))
> 
> (define (knapsack loi W)
>   (let ([loc (ini-todo loi W)])
> (define (fn-for-n cur todo acc)
>   (let* ([nbs (graph-nbs loc cur W)]
>  [nacc  (if (> (node-value cur) (node-value acc))
> cur
> acc)])
> (if (empty? nbs)
> (fn-for-lon todo nacc)
> (fn-for-lon (append nbs todo) nacc
> 
> (define (fn-for-lon todo acc)
>   (if (empty? todo)
>   (node-value acc)
>   (fn-for-n (first todo) (rest todo) acc)))
> 
> (fn-for-lon loc (node 0 0 (list)
> 
> (define h1 (list (obj 2 2)))
> (check-equal? (node-value (knapsack h1 2)) 2)
> (check-equal? (node-value (knapsack h1 1)) 0)
> 
> (define h2 (list 

Re: [racket-users] Experiences with Racket on RISC-V?

2019-01-07 Thread 'Paulo Matos' via Racket Users



On 05/01/2019 00:55, David Thrane Christiansen wrote:
> Hi Paulo et al,
> 
> Thanks for the info! It sounds like Racket or Racket-on-Chez is a bit
> of a risky bet for a RISC-V project with a quick turnaround, but I'll
> keep my eyes peeled for the future.
> 
> Thanks again!

Hi,

I don't really understand the risky bet comment. What's a risky bet? To
use Racket on RISC-V for production? Well, yes, it doesn't run yet.
RacketCS doesn't compile because the RISC-V backend for Chez is not
finished, Racket doesn't compile because libffi, at least, hasn't been
ported to RISC-V.

However, it's not a risky bet to support the porting of Racket for
RISC-V because both are really mature projects which are here to stay
and lots can be done on RISC-V since the base ISA's and some extension
specs have been frozen.

Kind regards,

Paulo Matos

> David
> 
> Den tor. 3. jan. 2019 kl. 04.29 skrev Paulo Matos :
>>
>> Hi,
>>
>> Thanks for CCing me on this. I have been involved in the RISC-V
>> community for awhile and I am interested in getting Racket on RISC-V. I
>> have started porting Chez to RISC-V as a side project as currently I
>> have no clients paying me to do so. Therefore, as you would expect, it's
>> going slow. The good news is that the little porting I did is online[1]
>> and I am accepting PRs. :)
>>
>> If I can help with anything else please let me know. Things are slow on
>> my side until the 7th as I am on holiday but I will read all the racket
>> related messages by then and reply if I see I have anything to add.
>>
>> Paulo Matos
>>
>> [1]  https://github.com/LinkiTools/ChezScheme-RISCV/
>>
>> On 03/01/2019 02:59, Neil Van Dyke wrote:
>>> (CC-ing Paulo Matos.)
>>>
>>> I expect RISC-V to be a top architecture platform for systems
>>> researchers doing open science, including some language/compilers
>>> researchers.  And for CS students in systems classes.
>>>
>>> RISC-V is also looking to be important for a more open hardware platform
>>> for some industry, and for nations and user bases who care about that.
>>>
>>> This is a good, accessible overview of RISC-V, by Krste Asanovic:
>>> https://www.youtube.com/watch?v=QTYiH1Y5UV0
>>>
>>> I'd love to see Racket started towards RISC-V, by being tested working
>>> well on the current RISC-V boards (and on a good open source emulator).
>>>
>>>
>>> BTW, a second-priority, open-ish target architecture that might be also
>>> be on the horizon for Racket is Power9.  Were Racket to also go there, I
>>> think it would make sense for IBM / Red Hat to fund that, somehow.  (If
>>> someone wanted to do this unfunded, you could use an emulator, and ask
>>> raptorcs.com to kindly let you have remote access to a Talos II.  But
>>> IBM doesn't need charity. :)  Power9 would not be done to the exclusion
>>> of RISC-V, but be complementary.
>>>
>>> (I also still use amd64/x86, arm, and (openwrt) mips, of course.  No
>>> slights to those.)
>>>
>>>
>>> David Thrane Christiansen wrote on 1/2/19 7:38 PM:
 Hi all,

 I'm just wondering if anyone here has experience running Racket on
 Debian on RISC-V, either positive or negative. There is a Debian
 package, at least, but language implementations are often one of the
 more challenging things to make reliable on a new architecture.

 In case it matters, the GUI part is not relevant for what I'm
 interested in.

 Thanks!

 David

>>
>> --
>> Paulo Matos
> 

-- 
Paulo Matos

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.