
can anyone please clarify this for me, #lang racket
vs i.e #lang racket/gui
are those language having different libraries ?

looking at docs, #lang racket/gui
includes by default some libraries, but you could do that yourself with #lang racket
too

is that via require
?


I note their discord server has an IRC bridge - interesting as IRC support in slack is no more.

in Dr Racket, i can’t locate the auto-complete and auto-comment key-binding

Ranked Programming implemented in Racket: http://caml.mthimm.de/pub/Rienstra_2019.pdf


I wanted to generate powersets in Racket, and ended up with (define (powerset-stream lst)
(cond [(empty? lst) '(())]
[else
(let ([rst (powerset-stream (rest lst))])
(stream-append (stream-map (λ (x) (cons (first lst) x))
rst)
rst))]))

It seems to do the right thing, but even as a stream memory usage goes up, probably due to the stream caching?

So, let’s try it as a generator — I found this on S.O: https://stackoverflow.com/questions/25291125/racket-how-to-define-a-recursive-generator-like-python

Giving me (define (powerset s)
(generator ()
(cond [(null? s) (yield '())]
[else
(for ([e (in-producer (powerset (cdr s)) (void))])
(yield (cons (car s) e))
(yield e))])
(void)))

Which also works.

However, in that S.O post, it’s mentioned that this is terrible — but I don’t understand why?

Where does it say it is terrible?

Under “Side comments”: JFYI, this is not really a good way to do this if you care about efficiency (rather than play around with generators).

s/terrible/inefficient/

I think it is a case of using a sledgehammer to crack a nut.

The generator example will internally use more machinery than a simple list based one.

In your example where you want to generate one subset at a time it might be ok (I assume you are looking into streams / generators because the power set is huge).

Yes — well, hundreds of thousands items it was.

The stream one worked fine, but consumed a growing amount of memory.

The list based version is btw named combinations
fwiw.

There is also in-combinations
that only generate one at a time.

There is a standard library one??

I should not be surprised.. batteries included.

Hmm. Now I am curious - how is in-combinations implemented?


My racket-fu does not extend yet to understand that….

I think the clue is “Gospers Hack” which means we need to look up the algorithm.

i m trying to build an HTML builder in a graphical way, so far i have read about the GUI toolkit and the racket/draw but i need more suggestion on how to go about it. I want to draw a rectangle which will generate a div layout containing css property of the size of that rectangle, and also a way to finally preview the output.

But I guess the take-away is that we can trust in-combinations
to be efficient.

Yeah…

Thanks for your help.

is there a way in Racket to get some sort of diff of two byte arrays?

byte strings, I should say

@sergej Maybe this? https://github.com/tonyg/racket-diff-merge/tree/master

yeah, maybe :slightly_smiling_face: I’ll try it, thanks

@kokou.afidegnon I think implementing a html builder in html (eg use racket webserver for generating page, and then some js for things like drag and drop) would much easier approach

@nma.arvydas.silanskas i tried with the JS approach, it gave me some tough time, let me try again

I mean a task you chose is tough

yes,

but i think i need it for RAD

However, I think those other things were essentially rejected with the statement, “But, I think we should think bigger”

One can do all of these things

is there any way to bridge 2htdp/image and pict? for use with big bang.

in-combinations uses in-producer
to make a sequence (and a sequence is lazy without caching & “simpler” than a generator I guess)

@soegaard2 Gosper’s hack is for all combinations of k
elements. Not for powerset.

You can use pict->bitmap
from pict

But if k runs from 0 to the length of the list, you will get all subsets.

ah, sensible enough.

Yes. But you can also get all subsets with k=#f
and the code in that case doesn’t use the hack.

Good point.

Hey Matthew, I would like to know how you’re going to get around permission errors on windows and linux with the new zo files?

@mflatt ^ wooks

woops*

Anyway, as I understand it, as of 7.4, zo files can replace old ones during load time.

No. A distribution build (e.g., an installer) has “.zo” files in the right format for the distribution’s OS and Racket VM.

This seems like windows would complain if the zo files are in C:/Program Files/Racket or something like that.

AH

Okay, that makes a lot of sense.

Thanks.

@xinhuang.abc has joined the channel

Hi, does anyone know how to use Racket FFI to get a global variable in objective-c. The one I am trying to get is NSSquareStatusItemLength. Thanks!


According to this, it is a constant.

Oh - sorry! I somehow read you mean “how to set”.

:slightly_smiling_face: I tried with get-ivar which seems to work with instance variable…

@xinhuang.abc I think you want something like (get-ffi-obj "NSSquareStatusItemLength" the-appkit-lib _double)
or (define-appkit NSSquareStatusItemLength _double)
if you’ve defined define-appkit
using define-ffi-definer
. That is, I think Objective-C’s global variables and functions are just like C global variables and functions.

FWIW it is seems the value is –2. http://lux.graphics/doc/cocoa/appkit/constant.NSSquareStatusItemLength.html

Thank you!

@ryanc get-ffi-obj should be the way, except it couldn’t get “NSSquareStatusItemLength” from "/System/Library/Frameworks/AppKit.framework/AppKit". weird…

I saw someone reporting a bug: The variable wasn’t available in Swift.

Maybe it isn’t a global variable - it could be defined as a constant in an .h file.

In the docs, switching from ObjC to Swift gets: https://developer.apple.com/documentation/appkit/nsstatusitem/1534224-squarelength

I see. Thanks!

You can check with nm -g in the terminal to see the exports: nm -g /System/Library/Frameworks/AppKit.framework/AppKit \| less

But still - it is odd that is documented as global variable.

So there’s a common practice in Racket where you define a syntax that errors when you invoke it, and then syntax-parameterize
or ~literal
on it.
E.g.,
;; while.rkt
(define-syntax break #f)
(define-syntax continue #f)
(define-simple-macro (my-while blah blah)
yada yada)
But then someone else could also do:
;; for.rkt
(define-syntax break #f)
(define-syntax continue #f)
(define-simple-macro (my-for blah blah)
yada yada)
And when clients use both modules, identifiers clash.
There are several solutions, but I don’t feel satisfied with them:
1) Share break
and continue
identifiers in both implementations, but this requires macro implementers to talk to each other. Definitely not possible in practice.
2) Clients could (require (rename-in "for.rkt" [break for-break] [continue for-continue]))
and use new id names inside for
instead, but this seems unnecessarily complicated.
3) Look for break
and continue
literally, but that means (my-while ... (let ([break (thunk 1)]) (break)) ...)
is probably not going to do what I want.
Is there a nice solution to this problem? For instance, is there a way for clients to “merge” two break
into one somehow?

I think moving the clashing identifiers to a common module is the most robust solution, if not the easiest

That would indeed be the easiest if there’s only one implementer.

Yes. I don’t think there’s any way around the communication costs of getting two implementors to agree that their identifiers are the same conceptual thing

Maybe a control-flow-syntax
package could define some common syntax parameters

So I’m still unsure what exactly the big gain from doing this is…I saw it last week at racket school but I’m not sure I was sold on the reasoning for exposing something as an error outside the forms that are meant to enclose it

Giving it a binding would let you attach other metadata and such. Like you could make it add mouseover tooltips. Also it would cooperate with drracket’s “rename identifier” operation

Really though the main reason I like it is that it just… feels like it makes sense. It’s a name. Names deserve bindings. I like when things cooperate with that intuition.

It’s not a strong or well formed intuition. Like, what does that mean for function keyword arguments? Should those be bound identifiers? I don’t think so, but I’m not sure why.

Specifically for syntax parameter, defining syntax parameter beforehand allows you to do things like this:
(define-syntax-parameter break ...)
(define-simple-macro (my-for ...)
(syntax-parameterize ([break ...])
...))
(define-simple-macro (looper x e)
(my-for ([x 10]) e))
(looper x (if (odd? x) (break) (print x)))
Without syntax parameter, getting break
to work in macros that expand to my-for
is going to be difficult.

why are units so seldom used? is it a legacy technology nowadays?

Matthias used it recently: https://github.com/mfelleisen/7GUI/tree/master/UnitMVC

I’ve used units recently to test some code with two different implementations.