
Is there a catch-all type in typed-racket which subsumes both lists and sets? Something like java’s Collection
type

Thank you! Also, here’s a doc preview before the online docs are done. (EDIT: Thread has re-upload of this PDF with fixes)

> (Remember #NAME? , etc. in Excel?) Nope. Don’t remember #name?.

Other than that - excellent documentation.

There’s some minor errors in there to patch up. Appreciate the feedback too, thank you!

Re-upload with changes:
• Fixed typos • Added clarification that only necessary work is done on a refresh. • Added defproc
for discovery-phase?
• Changed mention of #NAME?
to something clearer

What’s this character called?

Reference mark. It’s like an asterisk in the context of footnotes, except you’d find it in Eastern texts. https://en.wikipedia.org/wiki/Reference_mark

Taking a quick look, you might be able to adapt my continuation make trick from datacell to get (dynamic) cycle detection, instead of having a depth limit: https://github.com/florence/datacell/blob/master/private/cell.rkt#L40\|https://github.com/florence/datacell/blob/master/private/cell.rkt#L40

@florence I was wondering if there was a better way to do that. Thank you!

There might actually be a better way to do it, such that you allow cycles if they stabilize. Let me see if i can find the paper…

I figured it was like a case of the halting problem and that any solution would be empirical. I’d love to see this

I’ll also put in a link to datacell
in the docs for comparison so that others can weigh it when choosing a library.


There are lots of approximations: if the data forms a semitlatice it should always stabilize.
I wrote datacell in like 30 minutes it probably not very good and missing lots of features :P

Thank you for the paper! I’m not at post grad reading level, so what are some of these notations called? No need to explain what they are, but I have some homework to do before I can understand this paper

Oof… not sure what the names of a lot of that is. They have code somewhere let me find it…

Ug the new DL interface is terrible. @samth is there a convenient gh repo for this paper somewhere?

If I can add on: @soegaard2 you had actually sent me Martin Erwig’s functional graph paper and I had trouble in some sections there as well. I guess my question is a bit more general: What would you advise a CS student with a Bachelor’s to learn to be able to understand most CS research papers? If I’m going to run into more papers, I’d really love to be able to understand them as intended.


@deactivateduser60718 You sort of pick up on the notation after a while. (You also learn which sections to skip). For semantics I learned a lot from LiSP by Queinnec. Sometimes it helps to know a little Haskell or SML.

There’s Sequence

Hi, all. I’ve been off Slack — generally, not just Racket’s — for what feels like a few months. I’m back, somewhat selfishly because I have a question.

This is long for a Slack post, so first the TLDR:
Is there an equivalent of namespace-mapped-symbols
and identifier-binding
for when you don’t have a module->namespace
namespace? And instead merely have fully expanded syntax in some namespace?
Given some module with #%require
s, I want to be able to enumerate all those imports, and, find where they are defined — without using module->namespace
.

[[Oh great, I heard about the Slack-no-markdown thing. Hunting through the options to fix that…. fixed.]]

The background:
The last few weeks, I’ve been working on having Racket Mode make better use of drracket/check-syntax.
Before: racket-check-syntax-mode has been a limited read-only thing. You turn it on, and you can navigate defs and uses, and rename things. But you have to disable it to do general editing again.
After: It would work more like background check-syntax in DrRacket. You can just edit, and after some idle timer delay, annotations refresh.
Before: Previously, racket-mode has relied on you having a live module->namesapce — i.e. you did a racket-run of the buffer you’re editing — to supply some feature likes visit-definition and completion.
After: I’d like racket-mode itself to no longer even attempt any of that. Instead, such features would come from racket-check-syntax-mode, and drracket/check-syntax. Benefit: You need not run your file, and side-effects of doing so. (Also benefit: I know some people who use racket-mode only for editing, and do racket
in a terminal. They could not enable racket-check-syntax-mode to run alongside racket-mode, and they wouldn’t even need the “back end server” part. It would a simple, passive, Emacs major mode.)
So far so good. Nothing is merged to master
yet, and probably won’t be for awhile. The UX seems pretty good to me, modulo various nits that can be fixed.
However. I have noticed one theme. drracket/check-syntax only knows about bindings — about definitions that are actually used. This matters for things like completion candidates — including fancy company-mode that can give you visit-definition for completion candidates. Remember, completion as a feature is to avoid typing the names of things that are available. Very often you want that to work the first time you are going to use something.
You might think that
syncheck:add-arrow/name-dup/pxpy
would be a great source of completion candidates for module definitions. But those don’t exist for unused definitions, because DrRacket doesn’t draw arrows to something from nothing. :) Instead a better source issyncheck:add-mouse-over-status
annotations with a “bound occurrence(s)” text (the “no bound occurrences” ones are the ones that are missing, that don’t need arrows).Similarly, the
syncheck:add-jump-to-definition
annotations seems like a great source of completion candidates for imported definitions. But again, they only exist for imported definitions that are already used — not all that could be.
In both cases, the theme is completion candidates is a bigger set — things that could be used, even if they aren’t yet.

So I’ve been working on supplementing what drracket/check-syntax supplies. (Someday I could propose a PR to that, but for now I’m just trying to figure things out, and, make something that works with older versions of Racket.)
So far, I have been able to get the list of imports by parsing the #%require syntax, using module->exports, and replicating the set logic for prefixes, renames, and except-ins.
So I do have a list of completion candidates. “It works”.
Where I am stumped is, supporting the fancy company-mode feature, where, for each candidate, I could also supply the location. That is, identifier-binding doesn’t seem to work unless there is already a binding for the import. What do I do?
(I started to experiment with making some skeleton module, just inserting uses of each import (i.e. making “dummmy” bindings, so that identifier-binding could find those). But I’m not having luck, initially, plus it seems like a kind of smelly approach, and I must be overlooking some better way.)

Welcome back! Tricky questions.
What are the rules of the game? We are editing a file in racket-mode and during editing, we like to get a list of completion candidates. Does the “when you don’t have a module->namespace
namespace” mean that we can’t run the file we are in (including using symbols from previous runs)?

Hi @soegaard2! Yes, from a user POV it means you no longer need to racket-run
the buffer you’re in. You will get accurate completion candidates and visit-definition will work correctly.

I have that already working, on my branch. It’s handy when you’re editing. It’s also handy when not editing — when just viewing/exploring some set of code files. I mean, for example, amusingly I’ve found it handy to navigate the source files for drracket/check-syntax
itself. :smile: In the old approach, you had to visit a new file, run it, and only then would you get accurate visit-definition. Because the old way depends on having a namespace from module->namespace
that’s “in” that file. Whereas the drracket/check-syntax approach depends on merely expand
-ing the file. So (if my terminology is correct), the file’s module is merely declared but not instantiated.

What I would like is for identifier-binding
to work with such a namespace, in which a module was merely expanded. (It would be nice if namespace-mapped-symbols
also worked in such a namespace, but, I’ve already got its equivalent by walking #%require
forms to make a set of imports that is ~= to what that would say, if it worked for such a namespace).

So the missing piece, for me right now, is really just identifier-binding
in a merely-expanded module namespace.

That way, I can have not just a list of completion candidates, but, a list of tuples — the candidate and where to find it. Which supports a nifty company-mode feature, to visit the definition of a completion candidate. So, I mean, I’m kind of getting into nice-to-have feature territory. But it’s something that worked with the old approach, so I’d like to keep it in the new approach. And also I’m just curious, how really does identifier-binding
work — or not — namespaces created in these different ways.

@greg I think you may want to use some tricks that @mflatt set up for me in Typed Racket.


Oh wow Quick glance that looks promising (and also unlikely I ever would have figured that out on my own :smile:). Thanks @samth and @mflatt I’ll try working with that!

@samth is probably a better person to discuss this with (I’m merely a TR user.) From my perspective it makes sense that if a contract cannot be generated then it is unsafe to use in untyped code. And part of the reason to use TR is safety.

For the code that @samth references, syntax-binding-set
and syntax-binding-set->syntax
is the modern, more-direct solution.

Should I change TR to use that?

I haven’t yet understood how it’s relevant to the problem that you describe, though, @greg.

@samth: Yes, probably.

I think a short summary of the problem is that if you have a namespace in which you’ve expanded a module, how do you create an identifier that appears to be inside that module

That you could give to identifier-binding
and it would work.

Ok, good! :slightly_smiling_face:

I mean I felt like that was a bit of a roundabout hack that I’d come up with, in the first place. “Given some expanded modules, extract its #%require
s into a new skeleton module syntax in a fresh namespace, and glom in some uses of all imports, so that identifier-binding
will work.” How to “glom in uses”, is what Sam was trying to answer. But @mflatt if my whole strategy is a big smell, of course please don’t hesitate to let me know. :slightly_smiling_face:

I guess if identifier-binding
is really “identifier-actual-binding”, I am trying write “identifier-possible-even-if-not-yet-actual-binding”.

Really just given some starting point, “I know module-path M provides var or stx ID”, I want to run down the chain of (re)provides until I get to the defining source. identifier-binding
the way I know how to do this, with module->namespace
. But maybe I should just chase it down myself using say module->exports
and module->imports
….

@greg If you want to chase it down like that, you might get some use out of these module reflection utilities I wrote: https://docs.racket-lang.org/rebellion/Module_Bindings.html

Specifically the module-provided-bindings
function https://docs.racket-lang.org/rebellion/Module_Bindings.html#%28def._%28%28lib._rebellion%2Fmodule%2Fbinding..rkt%29._module-provided-bindings%29%29

OK the plot thickens. I was putting together info for an issue, and I found if I use the user
scope it works. I was installing using the installation
scope when it failed.

Aha

It’s because the binary package catalog was setup for the user scope and not the installation scope

@notjack Thanks, I’m already up-to-speed on using module->exports
. But you’ve provided a really clean and well-named wrapping around that!

thanks!

!

Huh, why should the installation scope matter? Weird

I’ve never looked into the theory of these kinds of libraries so this might be a naive question but: why allow cycles at all? Even if they’re stable, they seem like they would lead to a great deal of user confusion.

Are there important use cases that require cycles?

Any stabilizing program cycle can be transformed in to an acyclic graph, but that transformation is 1: non-local, and 2: as bad as O(n^2). But youre right in general, most practical implementations rule out cycles either statically or dynamically. (this can be non-trivial though). What you want depends on the problem domain really

For example in the hardware world, cycles can be very useful for minimizing circuits. In Esterel there are some control problems that are a pain to express with cycles. But AFAIK in the FRP&Dataflow world cycles are usually disallowed.

(Cycles are also easier to reason about in the hardward and esterel world because your latice of values contains only three elements, meaning you can statically determine if something will stabilize. Not true for general dataflow)

(+cc @notjack) Alright, so I’m working on a macro as shown here: https://github.com/zyrolasting/kinda-ferpy/issues/2
I’m trying to translate a list of syntax objects a form that I can splice into a template. I’m still learning the various transitions between pattern variables and templates. Here’s some broken code so you can see the direction I’m headed.
(define-syntax (stateful-cell stx)
(define stx-e (syntax-e stx))
(define-values (dependency-options unused)
(parse-keyword-options (cdr stx-e)
(list (list '#:dependency
check-identifier
check-identifier))
#:context #'stateful-cell))
(with-syntax ([requested-dependency-bindings
(map (λ (spec) (drop spec 2)) dependency-options)]
[body unused])
(make-stateful-cell
(λ ()
(let (requested-dependency-bindings ...)
body ...)))))
I know this isn’t valid because with-syntax
has bindings to plain lists of syntax objects. What do I have to change to make the ...
s as shown in the body make sense?

Ah, I think I’ve got it. It’s closer than I thought. Don’t help me just yet, I want to see if I got this.

My guess is that there are different configuration settings for each scope.

The only reason I was using installation scope was that I figured it’s a docker container there should only be one set of packages, let’s just put them all in one place.

@deactivateduser60718 I highly recommend using define-simple-macro
for this. Feel free to get something working first before trying that however.

Yep, I already can tell cleanup is desperately needed. I got something working, and ended up here:
(define-syntax (stateful-cell stx)
(syntax-case stx ()
[(_ code ...)
(let-values ([(parsed-options unused)
(parse-keyword-options #'(code ...)
(list (list '#:dependency
check-identifier
check-identifier))
#:context #'stateful-cell)])
(with-syntax ([(requested-dependency-bindings ...)
(map (λ (spec)
(with-syntax ([orig/id (third spec)]
[body/id (fourth spec)])
#'(body/id (orig/id))))
parsed-options)]
[(body ...) unused])
#'(make-stateful-cell
(λ ()
(let (requested-dependency-bindings ...)
body ...)))))]))

Example expansions: main.rkt> (expand-once #'(stateful-cell 1))
#<syntax:/home/sage/Code/kinda-ferpy/main.rkt:70:11 (make-stateful-cell (λ () (let () 1)))>
main.rkt> (expand-once #'(stateful-cell #:dependency a other (if other 1 2)))
#<syntax:/home/sage/Code/kinda-ferpy/main.rkt:70:11 (make-stateful-cell (λ () (let ((other (a))) (if other 1 2))))>
main.rkt> (expand-once #'(stateful-cell #:dependency a other #:dependency b more (if other 1 2)))
#<syntax:/home/sage/Code/kinda-ferpy/main.rkt:70:11 (make-stateful-cell (λ () (let ((other (a)) (more (b))) (if other 1 2))))>

The only reason I went this far was because I didn’t see a single pattern spec I could use to capture zero or more #:keyword id id
followed by one or more of any expression.

I posted a comment in the GitHub issue thread so I don’t eat up too much space here.

FWIW syntax-parse
has patterns for matching zero or more
#:keyword id id`` . Can’t quote chapter and verse though.

To @notjack’s point, define-simple-macro
uses syntax-parse
. I didn’t read that part of the manual yet since I’d like time to digest what I already learned.

This is a pretty amazing, yet information-dense system!

So I’ve wanted a function to use with slideshow to draw text sized with a proportion of slide size, but is there a better way to do that than binary search? https://gist.github.com/takikawa/bd1cb0563bdf7a76cb88105b2e354b40

You can use get-text-width
which computes the width of a space to make an initial guess closer to the result than just a huge range from 0 to 1000.

Not a huge improvement though.

Yeah, the initial guess is definitely a bit silly. :stuck_out_tongue: That’s a good idea.

Hmm, then to me it definitely sounds like a general purpose library would be better off disallowing cycles and leaving that use case to other, narrower libraries targeted specifically at hardware design

do fonts come with properties like “here’s the width of one M”?

The method get-text-extent
can be used to find the size of a string (due to ligatures it is not enough to add the width of each character).
Maybe @asumu can use it?
But it seems Asumu also wants to rotate the text, which complicates things further.

The initial version of this that I wrote did a binary search with get-text-extent
but it’s easier (though I’m sure less efficient) to use text
to support its richer interface.

(constructing font%
objects is kinda tedious, but you have to do it to vary the sizes with get-text-extent
)

I’ve just now gotten the same error in another file while documenting the removal of my find-executable-path
.

@mflatt @samth I was still struggling with this until I realized that identifier-binding
needed to be given a piece of syntax from the expanded syntax. Then I spent some time wrestling with how to parse the expanded syntax to find the bit with the indentifier of interest, that I’d inserted. Given what fully-expanded syntax can do, this was looking pretty gross. Then through some process of free-association, desperation, and luck, I came across: 12.9.1 Information on Expanded Modules and the 'module-body-context
syntax property. (identifier-binding (datum->syntax module-body-context 'some-imported-id))
seems to work! That does need you to expand some syntax that you make up on the fly that require
s the module exporting some-imported-id
, and, the expansion seems to need with-module-reading-parameterization
etc. in order for identifier-binding
to be happy about instantiating things. But it seems waaaay simpler than I feared. However I will work with it some more to be sure.

p.s. I had tried things like namespace-syntax-introduce
and namespace-symbol->identifier
, but neither produced syntax that identifier-binding
was able to use to do its magic. So far, only using that 'module-body-context
syntax property seems to be the proper lexical context.

p.p.s. The 'module-direct-requires
and 'module-direct-for-syntax-requires
syntax properties looked interesting. They seemed like they might be a slightly simpler alternative to using module->exports
. But (a) they always seem to be #f
for me and (b) I do need to parse the #%require syntax anyway to determine what the “net” imports are, taking into account except-in prefix-in rename-in etc. … and that code is already written and working :slightly_smiling_face:

It looks like those properties got lost in the expander rewrite. At this point, possibly we should just remove them from the documentation; apparently, no one has missed the properties for the couple of years.

Ah OK. Well, I’m super happy that 'module-body-context
did not get lost — that turned out to be just what I needed!