louis77
2021-2-15 08:08:37

@louis77 has joined the channel


louis77
2021-2-15 09:38:46

Hi there - just a little hello from a new Racket user! A nice day to you all.


louis77
2021-2-15 09:51:44

I currently working my way through Racket Weekend from Jesse Alama. Bringing some experiences with Common Lisp, one thing I miss in DrRacket is the ability to send S-expressions from the definition window to the interactive window. Isn’t that something Racketeers miss?


louis77
2021-2-15 09:52:48

Probably a very noob question :slightly_smiling_face:



spdegabrielle
2021-2-15 09:55:23

Sorry for the terse response - at work!


louis77
2021-2-15 09:55:33

No that is perfect, thanks!


samth
2021-2-15 13:16:20

For example, (module m racket (let l () (l)) (define x x)) Doesn’t raise a runtime error


samth
2021-2-15 13:17:00

Similarly if some expression uses a continuation before that definition


samth
2021-2-15 13:17:10

Or if the definition is inside a lambda


samth
2021-2-15 13:18:13

Of course some special cases could be recognized but an error that happens only in particular special cases is not usually a good idea


evyatar2013
2021-2-15 16:45:02

Does racket have the ability to create variables with “hidden” compartments? Example of desired functionality: (define a (hidden-compartment 10 #hide-me 20)) (+ a 20) > 30 (define (my-function foo) (if (has-hide-me? foo) (unhide foo) (+ foo 10)))) (my-function a) > 20 (my-function 1) > 11


evyatar2013
2021-2-15 16:47:14

The key here is that unless the code “looks” for the hidden value the variable is masquerading as a plain ol’ integer


samth
2021-2-15 16:48:20

No, there’s not a general way to do something like that


evyatar2013
2021-2-15 16:49:10

dang, thanks for the quick response


samth
2021-2-15 16:51:21

Do any other systems you know of have something like that?


samth
2021-2-15 16:53:27

I think in general it would be very difficult to actually make a system behave that way consistently


evyatar2013
2021-2-15 16:55:22

For sure, but Racket does a lot of things I would consider very difficult so I figured it couldnt hurt to ask :stuck_out_tongue:

The closest I can think of is variable annotations in angr’s http://angr.io/api-doc/claripy.html#module-claripy.annotation\|claripy . But that’s a whole separate beast


badkins
2021-2-15 17:07:25

(define a (hidden-compartment 10 #:hide-me 20)) (+h a 20) ; => 30 (define (my-function foo) (if (has-hide-me? foo) (unhide foo) (+h foo 10))) (my-function a) ; => 20 (my-function 1) ; => 11 Not exactly what you want, but maybe a compromise :)


badkins
2021-2-15 17:10:28

@samth is it (theoretically?) possible in Typed Racket to redefine + to accommodate this w/o slowing things down?


samth
2021-2-15 17:13:36

It really depends on the semantics, but I doubt it


badkins
2021-2-15 17:16:38

I just meant the ability to redefine + in such a way, that at compile time, if the args were numeric, the normal + would be used, but if any of the args were of another type, a different function would be used. I think Julia might be able to do this.


badkins
2021-2-15 17:17:56

I suppose “overload” is a better term than “redefine”.


samth
2021-2-15 17:20:58

It’s certainly possible to do something like that but you’d probably end up with very few operations actually optimized, because most things would have to handle both cases (otherwise you’d be re-implementing everything twice)


samth
2021-2-15 17:22:20

This is basically how Haskell works, and they can optimize things, but you aren’t guaranteed anything


sorawee
2021-2-15 18:02:21

Note that this is possible:

#lang racket (begin-for-syntax (struct hidden-compartment (v hv) #:property prop:set!-transformer (λ (self stx) (syntax-case stx (set!) [(set! _ v) #`(set! #,(hidden-compartment-v self) v)] [(f args ...) #'((#%expression f) args ...)] [_ (hidden-compartment-v self)])))) (define-syntax-rule (define-hidable x v #:hide-me hv) (begin (define v* v) (define hv* hv) (define-syntax x (hidden-compartment #'v* #'hv*)))) (define-syntax (unhide stx) (syntax-case stx () [(_ v) (hidden-compartment-hv (syntax-local-value #'v))])) (define-hidable a 10 #:hide-me 20) a ;=> 10 (unhide a) ;=> 20 (set! a 40) a ;=> 40 (unhide a) ;=> 20 (define-hidable f (λ (x) x) #:hide-me 1) (f 10) ;=> 10 (unhide f) ;=> 1


sorawee
2021-2-15 18:03:30

Of course, when you pass a hidable to other functions, the “regular” variant is used, so it doesn’t work exactly like what you want.


dyllongagnier
2021-2-15 18:31:44

I think you could do this with impersonaters to some degree (https://docs.racket-lang.org/reference/chaperones.html?q=chaperone). However, they don’t work on very primitive objects like integers.


samth
2021-2-15 18:32:31

yes, many things can be chaperoned, but also many things can’t (anything opaque, roughly)


dyllongagnier
2021-2-15 18:39:08

I like the macro way better anyway. Less overhead and almost as general.


notjack
2021-2-15 22:53:59

as others have said, yes you can do this with impersonation but only for types that support impersonation. the specific mechanism is impersonator properties which let you stick key-value metadata on things https://docs.racket-lang.org/reference/chaperones.html#(tech._impersonator._property)


badkins
2021-2-16 00:58:53

What is the proper way to conditionally compile code? For example, I have a file that has two mutually exclusive sets of (require provide define-syntax-rule ...). When I made my first attempt, I got a “require: not at module level or top level” error.


badkins
2021-2-16 00:59:43

I suppose I could put the if within the require.


badkins
2021-2-16 01:00:14

Nope :)


badkins
2021-2-16 01:13:44

Wrapping them both in begin works. That allows me to simply comment/uncomment one or the other.


samth
2021-2-16 02:05:57

I think the usual approach is to have a macro with some compile time code that decides which one to do


jestarray
2021-2-16 03:26:45

how do i install a racket package without internet? im using my friends VPS that blocks all connections by default and i dont wanna bug him to whitelsit


jestarray
2021-2-16 03:27:14

think png-image is the name of the package i need to be installed offline


samth
2021-2-16 04:28:30

I would download the source code (via git, or you can get a tarball of a git repo from github) and then use raco pkg install locally