joergen7
2017-9-26 07:06:35

Redex seems to be geared towards Reduction Semantics, which I really dig. But suppose you were to define a reduction relation as a Structural Operational Semantics instead. To define the step relation playing SOS’s premise-conclusion game would you rather a) define a reduction relation and encode the premises as side-conditions or b) define a judgment form even though I’ve only seen people use these for typing rules? Or is there a third option I’ve just not stumbled over?


leafac
2017-9-26 09:16:19

I’d use a judgment form for that. I see people using judgment forms for all sorts of things besides typing rules. For example, in An Introduction to Redex with Abstracting Abstract Machines 1, Van Horn uses them for everything from a lookup relation to operational semantics.


joergen7
2017-9-26 09:24:03

thanks @leafac. (it’s good to hear from you btw.)


joergen7
2017-9-26 09:25:00

I guess I’ll try a judgment form then.


joergen7
2017-9-26 09:27:00

yes, the link you sent me does exactly what I was asking about. A natural semantics is also an SOS.


joergen7
2017-9-26 09:27:28

afaik.


mtelesha
2017-9-26 13:50:48

Loops hurt so bad



robert.postill
2017-9-26 13:59:15

@robert.postill has joined the channel


leif
2017-9-26 18:26:00

@mflatt I can never remember which is preferred: module-path-index-resolve or resolve-module-path-index.


leif
2017-9-26 18:27:06

I’m thinking of putting a note in the docs, but since I can’t remember which is preferred, I’m not sure which to recommend.


mflatt
2017-9-26 18:36:26

@leif Although I once had in mind that module-path-index-resolve would be preferred, resolve-module-path-index does slightly more. So, I found it tricky and not obviously worthwhile to pick on as preferred.


leif
2017-9-26 18:39:09

@mflatt Ah, yes, that’s what it was. Thanks.


ben
2017-9-26 19:22:06

@samth just noticed, TR doesn’t register a type for vector in (vector 1 2 3). Should I submit a PR to call add-typeof-expr in the part of tc-app that’s doing the type checking?


samth
2017-9-26 19:22:18

@ben yes


oldsin
2017-9-26 21:37:35

@oldsin has joined the channel


leif
2017-9-26 21:54:11

@mflatt How can I construct a module declaration?


leif
2017-9-26 21:55:05

Like, I know I can use dynamic-require to instantiate and/or visit it, and I can use namespace-attach-* to attach a declaration of an already declared module.


samth
2017-9-26 21:55:29

@leif eval is the usual way


zenspider
2017-9-26 21:56:27

@lexi.lambda you had some network code (http, maybe?) in here the other day that used some call/thunky form I’d not seen before… I don’t remember it’s name. help?


leif
2017-9-26 21:56:41

@samth Ya, but won’t that also eval it? Hence also visiting and instantiating it?


samth
2017-9-26 21:56:51

no



leif
2017-9-26 21:57:14

Okay then. If I have a module on my filesystem, is there any way to declare it?


leif
2017-9-26 21:57:36

Like, say I want to declare foo.rkt


samth
2017-9-26 21:57:40
> (eval '(module m racket (display 1)))
> (require 'm)
1
>

leif
2017-9-26 21:57:48

Fair.


zenspider
2017-9-26 21:58:28

that was it… thanks. I’m using port->string (post-pure-port (string->url ... and not sure how it’ll differ but I want to poke


leif
2017-9-26 21:58:42

That does work for anonymous modules (so to speak), but I’m not sure how to get that to work for ones that are on the filesystem. I mean, I could read it first, but then wouldn’t it be a different module?


lexi.lambda
2017-9-26 21:59:16

@zenspider port->string already closes the port, so I think it should be equivalent.


zenspider
2017-9-26 21:59:21

I want to build a simple webapp for the server side of a client I already wrote in racket. is there something like ruby’s sinatra I can start with?


lexi.lambda
2017-9-26 21:59:34

the web-server package.


samth
2017-9-26 21:59:52

@leif why do you want to avoid visiting it?


shu--hung
2017-9-26 21:59:58

@leif I thought dynamic require (void) does the declaration


samth
2017-9-26 22:00:37

@zenspider you might like http://lisp.sh/crud-web-api-in-racket/


zenspider
2017-9-26 22:00:40

huh. why do I already have that installed? I guess it is an auto-install


lexi.lambda
2017-9-26 22:00:53

it’s part of the main distribution.


zenspider
2017-9-26 22:01:33

oh… but the doco says package. hrm


samth
2017-9-26 22:01:40

@leif as @shu—hung suggests, (dynamic-require "foo.rkt" (void)) may be what you want, if you’re ok with visiting the module


leif
2017-9-26 22:01:42

@samth Because I don’t want to run the module, nor do I want to expand the module.


lexi.lambda
2017-9-26 22:01:58

@zenspider the main distribution is a set of packages. base is minimal racket.


samth
2017-9-26 22:01:59

@leif declaration involves expansion


leif
2017-9-26 22:02:18

Mm…good point.


leif
2017-9-26 22:02:36

Remind me the difference between visiting and expanding in this case then?


lexi.lambda
2017-9-26 22:03:00

@zenspider the main distribution has a lot of things in it. you can see them here: https://pkgs.racket-lang.org/package/main-distribution



zenspider
2017-9-26 22:03:26

so lisp.sh uses serve/servlet and web-server suggests stuffer chains… I assume the lisp.sh thing is more straightforward


zenspider
2017-9-26 22:04:01

I think I just never noticed rackunit and the like listing as packages in the doco


samth
2017-9-26 22:04:12

@zenspider which docs for web-server suggest stuffer chains?


lexi.lambda
2017-9-26 22:04:15

@zenspider you probably want to look here, not at the place #lang web-server deep links to. http://docs.racket-lang.org/web-server/index.html


samth
2017-9-26 22:04:24

lexi.lambda
2017-9-26 22:04:49

@samth #lang web-server indexes into a weird spot for beginners.


zenspider
2017-9-26 22:05:05

@samth I searched for web-server, clicked on the module result, and that drops you into section 3: stateless servers


zenspider
2017-9-26 22:05:14

the example at the top of that is a stuffer chain


samth
2017-9-26 22:05:18

@lexi.lambda that’s (partly) because #lang web-server isn’t really for beginners


samth
2017-9-26 22:05:36

it ought to have a different name


leif
2017-9-26 22:05:37

“That is, the expander instantiates any variables defined in the module within begin-for-syntax, and it also evaluates all expressions for define-syntaxes transformer bindings.”


leif
2017-9-26 22:06:26

If that is the case, and declaring a module requires visiting it…


lexi.lambda
2017-9-26 22:06:28

@samth #lang web-server/stateless? or #lang web-server/continuation? not that it can be changed now.


zenspider
2017-9-26 22:06:42

#lang web-server/gah


leif
2017-9-26 22:07:00

then its not at all clear how declaring a module and visiting a module differ. Like, is it possible to visit a module without declaring it, but not the other way around?


zenspider
2017-9-26 22:07:06

maybe the module link should drop into section 1 ?


lexi.lambda
2017-9-26 22:07:22

@zenspider the web server library is pretty old. if you stick to a good subset of it, it works pretty nicely. but there’s some weird stuff in there.


shu--hung
2017-9-26 22:07:32

@leif it is also possible that some module is copied from another namespace


shu--hung
2017-9-26 22:08:01

I think in that case declaration will happen, but maybe not visiting


lexi.lambda
2017-9-26 22:08:13

@zenspider it would be nice to write a small layer on top of the web server that gives it a more consistent, modern interface. I started doing that at one point, but then I got roped into writing my programming language.


samth
2017-9-26 22:08:20

me too


zenspider
2017-9-26 22:08:31

haha


leif
2017-9-26 22:08:33

@shu—hung that makes sense.


shu--hung
2017-9-26 22:08:36

iirc there’s some low-level functions that actually does the declaration work


zenspider
2017-9-26 22:08:45

“…and now I have 43 problems”



leif
2017-9-26 22:09:17

So then its safe to say that the ‘first’ time a module is declared, it must be visited, but any further declarations do not require further visits (but can optionally still do it.)


samth
2017-9-26 22:09:35

@leif the eval example does not visit the module


lexi.lambda
2017-9-26 22:10:27

@zenspider here’s a tiny example of one of my uses of the web server, which uses the most modern-feeling bits, I think. https://github.com/lexi-lambda/imgcap/blob/ae4a303c577b6d451a9f8d274b6f1907291b6530/imgcap/main.rkt


zenspider
2017-9-26 22:11:13

if I’m keeping an in-memory db… is there some hook or signal or something I can register to save to disk before the process quits? I don’t see anything on serve/servlet


leif
2017-9-26 22:11:15

@shu—hung Okay, thank you.


zenspider
2017-9-26 22:11:29

@lexi.lambda awesome. thanks


samth
2017-9-26 22:11:30

@zenspider you might be interested in https://github.com/samth/ella


leif
2017-9-26 22:12:19

@shu—hung So it seems like all declaring a module is…is applying that parameter’s function…


leif
2017-9-26 22:12:28

Which makes a lot more sense. :slightly_smiling_face:


leif
2017-9-26 22:12:59

So now, if that is the case, I just need to find a way to call that function directly.


leif
2017-9-26 22:13:18

(Since I wan’t to declare a module on the filesystem without visiting it.)


zenspider
2017-9-26 22:13:33

ella is pretty


lexi.lambda
2017-9-26 22:14:29

@samth I have a bunch of utility functions and things sitting around that I’ve basically copied between various web-server projects because I haven’t felt like I have enough to put them into a package. Then I got stuck because I decided my web framework needed an ORM, and then I decided it would be really nice to have return-type polymorphism…


lexi.lambda
2017-9-26 22:18:22

I have some stuff that does signed/encrypted session storage using libcrypto, rails-style “flashes”, bindings to recaptcha, match expanders for HTML forms, a short-id generator, and a simple HTML sanitizer. Also some sendgrid integration for sending emails, but that’s probably pretty half-baked.


zenspider
2017-9-26 22:21:04

hrm… exit-handler isn’t like at-exit in that it adds a thunk to run at exit… instead, it assumes the entire exit process and doesn’t actually exit… what am I not getting?


zenspider
2017-9-26 22:21:31

AND! doesn’t actually run if via the cmdline?!?


zenspider
2017-9-26 22:21:52

(unless I manually call (exit))


zenspider
2017-9-26 22:22:44

should I be using (executable-yield-handler) instead?


lexi.lambda
2017-9-26 22:23:17

@zenspider my guess is that the exit handler isn’t really what you want. maybe you want a plumber? http://docs.racket-lang.org/reference/plumbers.html


zenspider
2017-9-26 22:25:21

yeah. that is strange. if I use executable-yield-handler it does NOT get called if I call (exit)… too tangled (yet not tangled enough?)


zenspider
2017-9-26 22:25:24

I’ll poke at plumbers


zenspider
2017-9-26 22:29:23

honestly… plumbers don’t make much sense to me.

> There is no guarantee that a flush callback will be called before a process terminates—either because the plumber is not the original plumber that is flushed by the default exit handler […]


zenspider
2017-9-26 22:31:14

ah. I shouldn’t make one. just use current-plumber


lexi.lambda
2017-9-26 22:32:52

@zenspider my understanding is that the reason things like exit-handler, executable-yield-handler, and current-plumber can be changed is to support things like DrRacket, but most programs will not touch them.


lexi.lambda
2017-9-26 22:33:18

you certainly don’t want (exit) in DrRacket to exit DrRacket.


notjack
2017-9-26 22:44:00

@zenspider Also, plumbers are for optimistic resource cleanup, where it’s acceptable if attempting to clean up the resource is abandoned. Custodian shutdown hooks are for things that absolutely must happen during cleanup, and as such they’re unsafe to use due to deadlocking / concurrency problems and you should be very careful about doing IO in them.


notjack
2017-9-26 22:44:25

if you’re writing stuff to disk you most definitely want a plumber flush callback


zenspider
2017-9-26 23:38:11

is there a way to hook cancelling the web server in the repl?


zenspider
2017-9-26 23:38:41

I can catch exit on the cmdline just fine… but that isn’t as clean as just running the code in the repl and then C-c C-c


zenspider
2017-9-26 23:39:07

looks like it calls bye, then shutdown-server… but that doesn’t have hooks


zenspider
2017-9-27 00:00:50

@samth I wound up expanding ella’s macros to include (_ method route (e args ...) ...) (arb code in body) and (_ method route e) (bare name)


zenspider
2017-9-27 00:01:19

such that:

(get #rx"/incr" (incr params))
(get #rx"/incr2" incr)
(get #rx"/incr3"
     (set! db (cons (length db) db)) ...)

samth
2017-9-27 00:01:35

Cool


samth
2017-9-27 00:01:51

I haven’t touched that code in a while as you can see


zenspider
2017-9-27 00:01:53

I am guessing I’ll mostly use the middle form


samth
2017-9-27 00:02:04

So I’m happy to take any changes you make


zenspider
2017-9-27 00:02:33

cool… question for you… is that first form in the examples file supposed to work at all? I’m guessing no?


zenspider
2017-9-27 00:02:53

I was tempted to extend the macro to regexp-ify a bare word


shu--hung
2017-9-27 00:26:55

@leif: rereading the doc again, now I’m not sure whether module declaration is actually performed by the default module name resolver


shu--hung
2017-9-27 00:28:15

the doc seems to say that when a module is declared, the current module name resolver will be invoked, not “the current module name resolver is invoked to declare a module”


leif
2017-9-27 00:46:17

@shu—hung lol, thanks.


leif
2017-9-27 00:47:05

Which I guess leads back to my original question. How can I declare a module (without visiting it)?


leif
2017-9-27 00:47:16

Which I suspect @mflatt probably knows.


mflatt
2017-9-27 01:42:39

@leif There’s no way to avoid running expand-time code in a module form if you start with the module in S-expression form. If you have a module in compiled form, you can eval the compiled module to declare it without running any phase of the module. (And if you want the declared name to correspond to a file, set current-module-declare-name.)


mflatt
2017-9-27 01:43:29

If you have a file that contains a module, then you probably want to set current-module-declare-name and current-load-relative-directory while you use load.


samth
2017-9-27 02:17:04

@zenspider that first form is indeed supposed to work. did it break?


zenspider
2017-9-27 02:45:53

@samth it didn’t work for me… but I don’t remember how/why.


zenspider
2017-9-27 02:46:00

could be user error :stuck_out_tongue: