kokou.afidegnon
2019-7-18 08:44:37

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


nma.arvydas.silanskas
2019-7-18 09:10:12

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


kokou.afidegnon
2019-7-18 09:11:26

is that via require?


spdegabrielle
2019-7-18 09:12:20

spdegabrielle
2019-7-18 09:13:08

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


kokou.afidegnon
2019-7-18 09:19:36

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


soegaard2
2019-7-18 09:37:58

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



stefan.kruger
2019-7-18 12:04:40

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))]))


stefan.kruger
2019-7-18 12:05:20

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


stefan.kruger
2019-7-18 12:05:55

stefan.kruger
2019-7-18 12:06:09

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)))


stefan.kruger
2019-7-18 12:06:17

Which also works.


stefan.kruger
2019-7-18 12:06:38

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


soegaard2
2019-7-18 12:09:28

Where does it say it is terrible?


stefan.kruger
2019-7-18 12:10:15

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).


stefan.kruger
2019-7-18 12:11:36

s/terrible/inefficient/


soegaard2
2019-7-18 12:12:03

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


soegaard2
2019-7-18 12:12:50

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


soegaard2
2019-7-18 12:13:34

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).


stefan.kruger
2019-7-18 12:14:21

Yes — well, hundreds of thousands items it was.


stefan.kruger
2019-7-18 12:14:50

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


soegaard2
2019-7-18 12:15:00

The list based version is btw named combinations fwiw.


soegaard2
2019-7-18 12:15:16

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


stefan.kruger
2019-7-18 12:15:16

There is a standard library one??


stefan.kruger
2019-7-18 12:15:34

I should not be surprised.. batteries included.


soegaard2
2019-7-18 12:15:57

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



stefan.kruger
2019-7-18 12:18:32

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


soegaard2
2019-7-18 12:19:39

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


kokou.afidegnon
2019-7-18 12:19:53

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.


soegaard2
2019-7-18 12:20:37

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


stefan.kruger
2019-7-18 12:20:58

Yeah…


stefan.kruger
2019-7-18 12:21:28

Thanks for your help.


sergej
2019-7-18 12:38:03

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


sergej
2019-7-18 12:38:19

byte strings, I should say


soegaard2
2019-7-18 12:40:12

sergej
2019-7-18 12:41:30

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


nma.arvydas.silanskas
2019-7-18 13:01:14

@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


kokou.afidegnon
2019-7-18 15:01:48

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


nma.arvydas.silanskas
2019-7-18 15:16:30

I mean a task you chose is tough


kokou.afidegnon
2019-7-18 15:28:40

yes,


kokou.afidegnon
2019-7-18 15:28:41

but i think i need it for RAD


badkins
2019-7-18 15:52:53

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


markus.pfeiffer
2019-7-18 15:58:09

One can do all of these things


matias
2019-7-18 16:33:28

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


ben
2019-7-18 16:45:29

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


ben
2019-7-18 16:46:11

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


alexknauth
2019-7-18 16:48:41

You can use pict->bitmap from pict


soegaard2
2019-7-18 17:21:39

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


matias
2019-7-18 17:26:01

ah, sensible enough.


ben
2019-7-18 17:43:55

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


soegaard2
2019-7-18 17:44:39

Good point.


leif
2019-7-18 18:41:02

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?


leif
2019-7-18 18:41:20

@mflatt ^ wooks


leif
2019-7-18 18:41:22

woops*


leif
2019-7-18 18:41:55

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


mflatt
2019-7-18 18:42:18

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


leif
2019-7-18 18:42:19

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


leif
2019-7-18 18:42:24

AH


leif
2019-7-18 18:42:29

Okay, that makes a lot of sense.


leif
2019-7-18 18:42:30

Thanks.


xinhuang.abc
2019-7-18 21:52:31

@xinhuang.abc has joined the channel


xinhuang.abc
2019-7-18 22:02:48

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!



soegaard2
2019-7-18 22:03:59

According to this, it is a constant.


soegaard2
2019-7-18 22:04:30

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


xinhuang.abc
2019-7-18 22:06:41

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


ryanc
2019-7-18 22:38:56

@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.


soegaard2
2019-7-18 22:48:31

xinhuang.abc
2019-7-18 22:52:20

Thank you!


xinhuang.abc
2019-7-18 22:54:41

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


soegaard2
2019-7-18 23:03:33

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


soegaard2
2019-7-18 23:03:56

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


soegaard2
2019-7-18 23:04:45

xinhuang.abc
2019-7-18 23:06:38

I see. Thanks!


soegaard2
2019-7-18 23:07:44

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


soegaard2
2019-7-18 23:07:59

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


sorawee
2019-7-19 00:58:58

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?


notjack
2019-7-19 01:25:09

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


sorawee
2019-7-19 01:33:49

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


notjack
2019-7-19 01:46:35

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


notjack
2019-7-19 01:47:51

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


beyer.andrew
2019-7-19 01:49:43

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


notjack
2019-7-19 01:54:29

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


notjack
2019-7-19 01:55:49

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.


notjack
2019-7-19 01:57:54

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.


sorawee
2019-7-19 02:01:50

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.


nma.arvydas.silanskas
2019-7-19 05:21:18

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


sorawee
2019-7-19 05:36:04

samdphillips
2019-7-19 06:15:56

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