notjack
2020-12-31 08:08:20

So the cut thing will definitely not work then? Good to know.


laurent.orseau
2020-12-31 09:05:07

It seems that syntax/parse has some backtracking mechanism (see #:commit) but it’s not clear how exactly. Is this better documented somewhere?


notjack
2020-12-31 09:32:50

I think the backtracking stuff is only relevant when syntax-parse fails and is trying to figure out what error message to show.


notjack
2020-12-31 09:33:11

The Fortifying Macros paper is what I’m vaguely remembering that from.



notjack
2020-12-31 09:36:57

Drat, the paper doesn’t describe the commit mechanisms at all.


notjack
2020-12-31 09:42:56

> When there are multiple alternatives, such as multiple syntax-parse clauses or multiple variants of a syntax class definition, they are tried in order. When an alternative fails, syntax-parse records the failure and backtracks to the next alternative. As alternatives are tried, syntax-parse accumulates a list of failures, and each failure contains a measure of the matching progress made. If the whole matching process fails, the attempts that made the most progress are chosen to explain the syntax error. Usually, but not always, there is a unique maximum, resulting in a single error explanation. Otherwise, the maximal failures are combined.


laurent.orseau
2020-12-31 09:48:10

Oh I see. Thanks, that’s helpful! A little strange too because this implies that backing can only fail too, which I’m not sure holds. I’m probably missing something though.


kellysmith12.21
2020-12-31 15:32:15

Do require and provide ignore scopes, under certain circumstances?


soegaard2
2020-12-31 15:40:29

No? But if you are producing require as the output, then beware that if stx=(require foo) then the context of stx and require can be different. If I recall correctly, the context is taken from the require identifier.


kellysmith12.21
2020-12-31 15:47:30

For context: I’m taking a require-spec, then using it to generate (syntax-local-introduce #'(begin (require <require spec>) (provide (all-from-out <required module path>)))) I thought that the syntax-local-introduce would prevent that require/provide fragment from interacting with other requires and provides in the module, however, the all-from-out seems to include all identifiers required from the module path, from anywhere in the module.


soegaard2
2020-12-31 15:50:52

I think, that’s just how all-from-out works. It doesn’t know about the require forms.


hectometrocuadrado
2020-12-31 17:21:54

Suppose we have two functions, func1 and func2. The user must call func1 before func2 (like create and destroy functions). Also func1 receives an argument that should be visible to func2 too. To achieve this we can do:

(define global-arg #f) (define (func1 local-arg) (set! global-arg local-arg) …) (define (func2) ;I can use global-arg …)

I was thinking if this can be done in a pure functional way. Is this possible?


soegaard2
2020-12-31 17:25:12

Well. Not sure if this is a good idea or not, but: • let func1 return two values: the current result and func2 This way the user can’t call func2 before func1 .


laurent.orseau
2020-12-31 17:25:42

You can use parameters. Func1 could also produce a value that you send to func2, so that func1 is a function


hectometrocuadrado
2020-12-31 17:48:55

I’d like that user had not to manage the func2 like a return value of func1. But I guess is one of the best solutions


hectometrocuadrado
2020-12-31 17:50:38

I have not used parameters so much, so I dont understand your solution xdxd


greg
2020-12-31 17:50:47

Although this “pattern” isn’t super common in Racket code I’ve seen, it’s not unusual for a “create” or “start” function to return a function that does the “destroy” or “shutdown”.


greg
2020-12-31 17:50:51

The web-server does this.


hectometrocuadrado
2020-12-31 17:50:54

I have to study parameters hehe


greg
2020-12-31 17:50:59

greg
2020-12-31 17:51:37

I think it’s actually a nice, clean, functional way to handle this.


greg
2020-12-31 17:52:08

I mean, it can be a PITA to keep track of the various “destroy” or “stop” or “shutdown” procedure values.


greg
2020-12-31 17:52:33

OTOH when an app gets a little complicated, sometimes you really do need those things to be explicit — things need to be started/stopped in a certain order.


greg
2020-12-31 17:52:55

@hectometrocuadrado ^


hectometrocuadrado
2020-12-31 17:55:41

@greg Thanks for your explanation!


hectometrocuadrado
2020-12-31 17:56:21

I think Im going to do that


jaz
2020-12-31 18:16:18

If the use pattern of these functions is very simple — you call func1, you do some work, and then you call func2 — this can be packaged up with a more convenient interface, like how call-with-input-file[*] works.


plragde
2020-12-31 18:48:23

I wouldn’t characterize parameters as purely functional (but they should be used when there are good use cases, I am not trying to denigrate them).


massung
2020-12-31 19:06:23

My preferred method of solving this is to pass a lambda to func1 which is executed and the “cleanup” is automatically taken care of at the end of the lambda:

(define (func1 body) (let ([x #f]) (dynamic-wind (lambda () (set! x (setup))) (lambda () (body x)) (lambda () (cleanup x))))) (func1 (lambda (return-of-func-1) ...))


spdegabrielle
2020-12-31 20:51:47

me1890
2020-12-31 21:37:46

but they were deceived for another IDE was created


spdegabrielle
2020-12-31 21:38:35

I’m assuming that is a LOTR reference?


me1890
2020-12-31 21:40:39

yes


me1890
2020-12-31 21:40:53

from the one ring inscription


samth
2021-1-1 02:35:28

To be super pedantic, the ring inscription itself says “one ring to rule them all, and in the darkness bind them”


samth
2021-1-1 02:35:43

And the line you quoted is from the explanation of it


hazel
2021-1-1 05:40:05

happy birthmasyear 43×47 y’all