sarna.dev
2021-3-14 09:58:51

@sarna.dev has joined the channel


sarna.dev
2021-3-14 10:49:51

hey, is there any benefit that parameters bring to the cmdline module? for me they seem like unnecessary clunkiness


soegaard2
2021-3-14 10:50:57

Parameters as in “command line arguments” or as standard Racket parameters?



sorawee
2021-3-14 10:59:13

Wait a minute, did we pay Slack for full history?


soegaard2
2021-3-14 11:01:07

Huh - I too see very old messages when I search.


sarna.dev
2021-3-14 11:01:21

thanks @sorawee


soegaard2
2021-3-14 11:01:29

sorawee
2021-3-14 11:01:45

Oh lol


sorawee
2021-3-14 11:02:17

I think this is a good opportunity to achieve everything


sarna.dev
2021-3-14 11:02:40

@soegaard2 parameters as standard Racket parameters. all the other CLI libraries I’ve used were more.. functional? and only in Racket you modify global state from within the arg parser, which I find weird


sarna.dev
2021-3-14 11:03:52

I’m used to passing functions to the parser, that take CLI args as (function) arguments


soegaard2
2021-3-14 11:05:58

@sarna.dev The user of cmdline determines what happens in the handlers-exprs, so you can do use simple globals, parameters or something else.


sorawee
2021-3-14 11:06:59

I think it’s true that the cmdline library forces you to use mutation. A more functional variant would definitely be better, but we probably can’t change the existing one since it would break backward compatibility.


soegaard2
2021-3-14 11:07:53

Many Racket libraries use parameters to represent global variables. The form parameterize makes it easy to temporarily set the globals to something different (and parameterize also works in programs with multiple threads).


sorawee
2021-3-14 11:08:22

@laurent.orseau will now sell his library :slightly_smiling_face:


laurent.orseau
2021-3-14 11:08:39

:sweat_smile: See also the global package


laurent.orseau
2021-3-14 11:09:19

I find it makes dealing with the command line much simpler, but it has its limitations.


sarna.dev
2021-3-14 11:09:20

@laurent.orseau it doesn’t support subcommands >:(


laurent.orseau
2021-3-14 11:09:40

It probably won’t anytime soon either


sarna.dev
2021-3-14 11:10:03

(the standard cmdline doesn’t either)


sorawee
2021-3-14 11:11:14

The standard cmdline doesn’t, but it’s possible to hack it to support subcommand. That’s the approach that raco pkg uses.


laurent.orseau
2021-3-14 11:11:54

Would be nice to have a package for this though


soegaard2
2021-3-14 11:12:05

Can I get a translation?


sarna.dev
2021-3-14 11:12:12

where’s the source code for raco? I can’t find it



sorawee
2021-3-14 11:14:01

Oh wait, it looks like I misunderstood. They actually kinda reimplement racket/cmdline?


sarna.dev
2021-3-14 11:14:09

it looks complicated as hell though lol


sarna.dev
2021-3-14 11:14:14

(for my beginner eyes)


sorawee
2021-3-14 11:14:28

Yes, definitely not for public use



soegaard2
2021-3-14 11:16:30

Do we need any slack email adresses?


sorawee
2021-3-14 11:16:51

This one claims to support “svn style command lines”, but it’s in the old package system: https://planet.racket-lang.org/display.ss?package=functional-command.plt&owner=cobbe


sorawee
2021-3-14 11:17:47

@sarna.dev I take it back. I think I was right. It uses racket/cmdline internally



sorawee
2021-3-14 11:18:36

which is used in the first file I linked above


spdegabrielle
2021-3-14 11:23:47

One for #general, and one for an #announce channel - it would make cross posting easier.


sarna.dev
2021-3-14 11:29:36

thanks for the pointers! I want to implement something like https://github.com/l3nz/cli-matic\|https://github.com/l3nz/cli-matic in Racket but I’m a very confused beginner >.> no idea what’s the “Racket style” and stuff, kinda afraid to make mistakes


sorawee
2021-3-14 11:35:21

You should give it a try! I’m sure people here can help you with the “Racket style” stuff


notjack
2021-3-14 12:05:49

And if you like, you could run resyntax over your code to get some racket style suggestions :p


greg
2021-3-14 12:26:06

I wonder what it would be like to try to use (abuse?) syntax-parse for command-line argument parsing.


notjack
2021-3-14 12:28:23

now you’re thinking with ~portals~ macros


greg
2021-3-14 12:31:02

Racket has quite a few “pattern matchers”. On the one hand, this can be a downside when learning, and, maybe some of the variety is historical accident? On the other hand, maybe the variety is useful specialization for various tasks? I don’t know to what extent it would be desirable, or even possible, to “unify” most of them? Or maybe it’s “just” a job for a user’s guide and/or cheat sheet format, to point out the various systems and give an overview compare/contrast.


greg
2021-3-14 12:32:53

[I’m not sure it’s some kind of huge problem. Partly just make sure people know some of the choices. Leverage common concepts they’ve already learned. Avoid getting bitten by details like ..+ vs. ...+.]


laurent.orseau
2021-3-14 12:36:41

@sarna.dev definitely do try. That’s the one way to make progress. We can help to the extent of our available time and knowledge


laurent.orseau
2021-3-14 12:38:55

@greg maybe the easy way is to rewrite match based on syntax-parse?


laurent.orseau
2021-3-14 12:39:29

Would be an interesting package :)


laurent.orseau
2021-3-14 12:41:32

I think it just means “sweet, you’re all done” with some food on the side


sschwarzer
2021-3-14 12:43:20

If I execute a file struct-test.rkt, #lang racket/base (struct foo (x y z) ; Shouldn't this prevent the creation of a `foo` name/binding? #:constructor-name foo-struct) ; Results in ; struct-test.rkt:12:8: module: identifier already defined ; at: foo ; in: (define-values (foo) 1) (define foo 1) with racket, I get an error message as shown in the code. I had expected that if I rename the constructor with #:constructor-name, there wouldn’t be a need to create a name/binding foo from the struct, so I could use the foo name for the define below.

Is the above error expected behavior and if yes, why?


sschwarzer
2021-3-14 12:59:59

When I saw that Racket uses Slack I was a bit concerned by the message storage limit. I think we have great “preserve-worthy” discussions here.

What are the plans when the trial period runs out? Just live with it? Create a website/subdomain with a searchable archive (if the data can be exported with the means provided by Slack)? Move to a different messaging platform? Something else?


laurent.orseau
2021-3-14 13:00:11

if you replace your last line with foo , you get the error:


laurent.orseau
2021-3-14 13:00:19

foo: bad syntax; identifier for static struct-type information cannot be used as an expression in: foo


laurent.orseau
2021-3-14 13:00:30

I suppose this is the match expander?


laurent.orseau
2021-3-14 13:02:15

Add the following property: #:name foooo and the error goes away


sschwarzer
2021-3-14 13:07:10

@laurent.orseau This seems to help, thanks! Unless someone can come up with a good excuse :wink: for the current behavior, I’ll try to find a ticket or enter one.


sschwarzer
2021-3-14 13:07:39

I now use unused-<name afterstruct> for the name.


laurent.orseau
2021-3-14 14:19:59

I don’t think it’s a bug though, i didn’t look too much into what this #:name does. Understanding this would probably explain why you didn’t obtain the behaviour you expected. Probably the docs can be improved though.


sorawee
2021-3-14 14:24:17

My wishlist features:

  • Autogenerate shell completion
  • Good error message (do you mean “x”? — perhaps based on edit distance)
  • Macro extensible

sorawee
2021-3-14 14:30:23

@samth should be able to answer that, but my impression is that we have been living with it (prior the standard trial enrollment)


sorawee
2021-3-14 14:32:21

I think it would be great if we can:

  • achieve everything until now
  • once the free trial is expired, achieve last month’s content, every month

samth
2021-3-14 14:38:45

Yes, the plan is to live with it, unless someone wants to take on the project of providing an archive


samth
2021-3-14 14:39:19

I’m happy to help with that but I’m not going to take it on myself


samth
2021-3-14 14:40:19

The name there is what’s used in match, for creating substructures, etc


ben.knoble
2021-3-14 14:44:40

I might be interested—depends on what the archive format is, but would a github repo that deploys (via pages) or something work? I can’t be responsible for creating the archive each month, but I can take the data (transform as necessary) and put together a barebones set of static pages. Search-ability is not my forte, though.


samth
2021-3-14 14:45:27

I can download things and send it to you


samth
2021-3-14 14:48:27

It’s working on creating the export. I’ll message you when it’s available.


ben.knoble
2021-3-14 14:49:54

^what samth said; the name contains syntax information that is used to cooperate with other components of racket. Cf. https://drive.google.com/file/d/1VHhJGhh44Sq9YCs30GkpMT9hCnCeTmD-/view\|https://drive.google.com/file/d/1VHhJGhh44Sq9YCs30GkpMT9hCnCeTmD-/view


samdphillips
2021-3-14 17:28:39

I think it’s an american colloquialism, but its not from the region I’m from.


laurent.orseau
2021-3-14 18:02:37

Why ‘macro’ extensible though?


philip.mcgrath
2021-3-14 19:21:47

Instead of #:name some-bogus-name, you can also write #:omit-define-syntaxes.


mikhailk897
2021-3-14 19:54:37

@mikhailk897 has joined the channel


sschwarzer
2021-3-14 19:59:42

@philip.mcgrath Thank you, I’ll try it. I now read the paragraph on #:omit-define-syntaxes and must admit I didn’t understand whether I only lose access to the name or if it has any other disadvantages that I’ll notice. (I’m not complaining; I don’t expect you to explain all the background in detail. :slightly_smiling_face: )


philip.mcgrath
2021-3-14 21:09:19

Yes, it’s confusing! (I still don’t understand when or why one might want #:omit-define-values.) AFAIK, if you don’t want the static information bound to the name, there’s no disadvantage: just, you might want to bind it to some internal name if you’re doing something more involved (e.g. using it to implement a match expander).


sschwarzer
2021-3-14 21:58:13

Here’s an outline of what I’m doing: http://pasterack.org/pastes/93106 .

The gist is that I’m creating the actual struct instances with a helper function make-group-params and I want to call the hash group-params, which is/was the original name from the struct type creation.

I still want the struct accessor functions like group-params-unset-value-title to be able to access the struct objects returned by make-group-params.


notjack
2021-3-14 22:06:04

Fun diff I generated with resyntax today. Old code: (define read-token (case-lambda [() (read-token #f)] [(count-lines?) (let* ([pos (if count-lines? (let-values ([(line col pos) (port-next-location (current-input-port))]) (list line col pos)) (file-position (current-input-port)))] [m (regexp-match non-delimiter*-regexp (current-input-port))]) (and m (match m [(token . _) (list (if (token-case-sensitive) token (bytes-downcase token)) pos)])))])) New code: (define (read-token [count-lines? #f]) (define pos (if count-lines? (call-with-values (λ () (port-next-location (current-input-port))) list) (file-position (current-input-port)))) (define m (regexp-match non-delimiter*-regexp (current-input-port))) (and m (match m [(token . _) (list (if (token-case-sensitive) token (bytes-downcase token)) pos)])))


soegaard2
2021-3-14 22:07:14

That’s pretty neat.


soegaard2
2021-3-14 22:21:26

I am attempting to get flomat running on Windows. I have built libopenblas.dll with msys2/mingw64 and now have a libopenblas.dll. I copied the dll to “C:\Program Files\Racket\lib” but Racket doesn’t find it anyway. Any ideas?


soegaard2
2021-3-14 22:21:31

samth
2021-3-14 22:24:40

There’s a logger for FFI search information


soegaard2
2021-3-14 22:26:20

Do I need to do more than choose “Show log” in the “View” menu of DrRacket?


samth
2021-3-14 22:31:13

You might need to change the log level


samth
2021-3-14 22:31:39

If you just show every thing at the info level I’m sure it will be there


soegaard2
2021-3-14 22:34:14

Found this:


soegaard2
2021-3-14 22:34:30

So the file exists, but isn’t loaded.


samth
2021-3-14 22:35:22

Might be 32 vs 64 bit, or any of many other things


soegaard2
2021-3-14 22:35:27

I think, I’ll try to modify the “OS library search path” instead.


soegaard2
2021-3-14 22:35:45

I think, everything is 64 bit.


alexharsanyi
2021-3-14 22:44:37

The DLL itself might have dependencies of its own (other DLLs), and if these are not found, the error is misleading, reporting that the original DLL cannot be found.

I would suggest using a tool such as “depends” to find out if all the dependencies of “libopenblas.dll” are actually found.


alexharsanyi
2021-3-14 22:45:47

this error is not Racket specific. the LoadLibrary call returns “not found”, without giving any indication of what was not found…


soegaard2
2021-3-14 22:46:17

That’s a good point. I get:


soegaard2
2021-3-14 22:47:21

The /mingw54/ paths look wrong


alexharsanyi
2021-3-14 22:48:41

I think Racket and ldd use different search paths — I would suggest downloading and using delends.exe


soegaard2
2021-3-14 22:49:33

Do you think, I can solve the problem by not moving the dll, and instead add the original location C:\msys64\mingw64\bin to some Windows search path ?


soegaard2
2021-3-14 22:50:22

alexharsanyi
2021-3-14 22:50:31

yes, that one


alexharsanyi
2021-3-14 22:51:06

you will need the 32 or 64 bit version depending on the actuall application, not OS. So if you use 32 bit Racket, you need the 32 bit version


soegaard2
2021-3-14 23:02:06

delends.exe showed where the problem were. First attempt at fixing the problem: not move the dll at all (let’s see if it works).


soegaard2
2021-3-14 23:05:11

That seemed to work.


soegaard2
2021-3-14 23:06:34

I don’t get why the OpenBlas project doesn’t provide binaries for Windows though. Seems odd to get everyone to compile them (and without any instructions).


notjack
2021-3-14 23:06:59

Another fun resyntax diff. Old code: (let ([key (list lexicon-file block-size block-pos)]) (hash-ref cache key (lambda () (let ([mlb (read-lexicon-block lexicon-file block-size block-pos)]) (hash-set! cache key mlb) mlb)))) New code: (define key (list lexicon-file block-size block-pos)) (hash-ref! cache key (λ () (read-lexicon-block lexicon-file block-size block-pos)))


samth
2021-3-14 23:09:49

@notjack can you generate hash-update too?


notjack
2021-3-14 23:11:39

@samth Not yet, the implementation is trickier. Consider this code: (hash-set! h k (+ (hash-ref h k) 5)) I need a way to check that the new value contains the expression (hash-ref h k) somewhere inside it, but I don’t care where


notjack
2021-3-14 23:12:23

syntax parse doesn’t have a built-in way to do that, I’d need to build a pattern expander or something similarly clever


soegaard2
2021-3-14 23:12:31

That’s pretty nice. From little-helper ?


notjack
2021-3-14 23:12:58

@soegaard2 yup, hope you don’t mind me using it as a test corpus :sweat_smile:


soegaard2
2021-3-14 23:13:36

Not at all. It’s kind of ideal, since the code is to the old side.


soegaard2
2021-3-14 23:14:22

I am kind of surprised, it still runs :slightly_smiling_face:


notjack
2021-3-14 23:15:23

no guarantees it still runs, resyntax only checks that it still compiles :p


sorawee
2021-3-15 03:11:41

Not sure if it will be worth it, but

(and m (match m ...)) could be rewritten to:

(match m [#f #f] ...) to reduce the drift


sorawee
2021-3-15 03:35:21

You can use recursive syntax class to find a pattern, though that doesn’t look like a good idea. What if it’s in quote?


sorawee
2021-3-15 03:37:54

Is there a way to defeat the separate compilation guarantee for module+? By that, I mean, I want:

#lang racket (module defn racket (provide mac) (define-for-syntax counter 0) (define-syntax (mac stx) (set! counter (add1 counter)) (println counter) #'(void))) (require 'defn) (mac) (module+ test (mac)) to output 1 and then 2.


notjack
2021-3-15 03:38:18

The fully correct solution would probably involve local expansion of some kind, but I’m fine with only partial correctness if the error cases are pathological


notjack
2021-3-15 03:39:31

Yeah I feel similarly about that one. It seems like weird code either way, so I’m not sure it’s worth recommending.


sorawee
2021-3-15 03:55:51

Obviously, define-for-syntax is a wrong thing to use here, but what could I use instead?

This almost works:

#lang racket (module defn racket (provide mac) (define-syntax (mac stx) (define counter (datum->syntax stx 'counter)) (define val (cond [(syntax-local-value counter (λ () #f)) => values] [else 0])) (println (add1 val)) #`(define-syntax #,counter #,(add1 val)))) (require 'defn) (mac) (module+ test (mac)) but it causes with another problem: we need to supply the right lexical context (which is very tedious), or else it will fail.

#lang racket (module defn racket (provide mac) (define-syntax (mac stx) (define counter (datum->syntax stx 'counter)) (define val (cond [(syntax-local-value counter (λ () #f)) => values] [else 0])) (println (add1 val)) #`(define-syntax #,counter #,(add1 val)))) (define-syntax (mac2 stx) #'(mac)) (require 'defn) (mac2) (module+ test (mac2))


rokitna
2021-3-15 05:11:56

Do you need (mac2) (mac2) to increment the counter twice even if they’re in the same module? If you don’t, then going ahead and passing the lexical information through is probably a good approach, even if it seems tedious.

If you do, then it seems like a set! approach would be more viable than using define each time. But I think you’re right about that being hard to carry over to submodules.

In that case, I think a good option is to kinda toss out the expectation that Racket’s existing module-level declarations are set up for this. Perhaps you can define your own module+ variant that reads the state of the counter in the outer module and creates a definition that initializes it to that value in the submodule.

At the extreme end (if none of that is good enough), perhaps you can break the separate compilation guarantee decisively by using the logger, having the defn module set up a log listener that acts as a server for the state of the counter, but doing some kind of handshake to ensure you only set up that listener if the same listener hasn’t already been set up.


sorawee
2021-3-15 05:18:04

Yep, I expect mac2 to increment the counter twice.


sorawee
2021-3-15 05:18:55

This is an annoying limitation of https://docs.racket-lang.org/mixfix/. I want to see if it’s possible to workaround the issue.


shu--hung
2021-3-15 06:41:04

Is this workaround usable? #lang racket (module defn racket (provide mac get-mac) (define-for-syntax counter 0) (define-for-syntax (inc!) (set! counter (add1 counter))) (define-syntax (mac stx) #'(begin-for-syntax (inc!))) (define-syntax (get-mac stx) #`'#,counter)) (require 'defn) (mac) (get-mac) (module+ test (mac) (get-mac) )


sorawee
2021-3-15 06:56:05

Not quite, but very close!

The problem with that approach is that mac could not be invoked in an internal-definition context. But I think I can make it expand differently based on syntax-local-context. Let’s see if it will work. Thanks!


sorawee
2021-3-15 06:58:06

Why does it work though?