pocmatos
2018-3-16 07:50:52

Is there a way to access low level integers in Racket? For example, I would like to build fast bitvector arithmetic, but I need access to raw-bytes or fixed size integers that wrap-around to do this. I initially thought that this was the idea of unsafe fixnums but I was wrong as they don’t seem to wrap around. Any suggestions or do I need to pull them from C using the ffi?


zenspider
2018-3-16 10:03:50

@pocmatos (are there two of you in here?) have you seen data/bit-vector ? maybe you can poke inside that?


pocmatos
2018-3-16 10:15:43

@zenspider two of me? don’t think so. Yes, I looked at data/bit-vector. From the docs, it looks like it was not using a compressed representation. However, I was just looking at the implementation and it’s using bytes as the representation. However, it has no arithmetic built on top of that, therefore my question on bitvector arithmetic. It seems I might have to implement it — data/bit-vector looks like a good start.


pocmatos
2018-3-16 10:15:50

@zenspider why would there be two of me?


zenspider
2018-3-16 10:17:00

God I thought I lost my mind… I went over to emacs in #racket and couldn’t for the life of me find this convo. :stuck_out_tongue:


zenspider
2018-3-16 10:17:14

@pmatos vs @pocmatos


zenspider
2018-3-16 10:18:18

While you’re poking around in there, also look at racket/private/vector-wraps


pocmatos
2018-3-16 10:18:26

thanks.


zenspider
2018-3-16 10:18:35

what are you trying to do anyways?


pocmatos
2018-3-16 10:18:55

interesting… why do I have a pmatos here as well… i wonder if that’s the username i have when logged in through my phone.


pocmatos
2018-3-16 10:19:40

@zenspider I am trying to emulate the rosette bitvector library using concrete values / as opposed to rosette symbolic.


zenspider
2018-3-16 10:22:05

I know nothing of rosette other than it was born up the road (I think)


pocmatos
2018-3-16 10:22:32

ok :slightly_smiling_face:


zenspider
2018-3-16 10:22:57

what does it do that, for example, plain racket integers don’t?


pocmatos
2018-3-16 10:22:58

anyway, my pmatos username seems to have been created by the github integration. I have never sent a message using it.


zenspider
2018-3-16 10:24:38

wow. they name the functions terribly on the rosette side


pocmatos
2018-3-16 10:24:53

@zenspider mostly, they are faster. implementing it on top of racket integers is what I have at the moment. However, there’s quite a bit to be gained after hours of arithmetic on racket integers if one uses a faster representation.


zenspider
2018-3-16 10:25:20

but it does look like the functional overlap between ints and rosette’s bitvectors is very close


zenspider
2018-3-16 10:25:50

the unsafe stuff would probably be the right way to go to get some speed out of it, but then you need to provide your own guarantees of correctness


pocmatos
2018-3-16 10:26:13

With racket integers representing a bitvector 32bits, means I need to do a lot of checks by myself to ensure proper wrap around, etc. Using a low-level representation would give me that almost for free.


zenspider
2018-3-16 10:26:53

The wrap around part was the only part I didn’t really understand… like, rotate the bits w/o dropping values?


pocmatos
2018-3-16 10:27:17

also, the reason not to use bitvectors from rosette using concrete values is because since they also support symbolic values every operation needs to check types, etc.


pocmatos
2018-3-16 10:27:38

(2*32 – 1) + 1 == 0


pocmatos
2018-3-16 10:27:58

thats (2^32 – 1) + 1 == 0


pocmatos
2018-3-16 10:28:10

for unsigned bitvector 32 arithmetic.


pocmatos
2018-3-16 10:28:35

but there are other operations which are faster if using a lower level representation directly.


zenspider
2018-3-16 10:29:05

ooooh… and you want fixed size. derp. ok… that was the part I really was losing you on…. this scotch is doing its job. :stuck_out_tongue:


pocmatos
2018-3-16 10:29:23

I actually was completely convinced that if I had an unsafe fixnum, it would wrap around but it turns out that’s not the cae.


zenspider
2018-3-16 10:30:47

AFAIK, unsafe JUST means it doesn’t do all the extra bounds/safety checks


pocmatos
2018-3-16 10:32:08

yes, i reached the same conclusion.


zenspider
2018-3-16 10:32:18

have you seen racket/fixnum and unsafe-fixnum?


zenspider
2018-3-16 10:32:27

I’m probably not helping at this point. :stuck_out_tongue:


zenspider
2018-3-16 10:32:35

(um… not to imply that I’ve helped at all)


pocmatos
2018-3-16 10:33:27

yes, had a read but doesn’t seem to be what I need.


pocmatos
2018-3-16 10:33:45

I might just create a super-simple C wrapper for stdint types and pull them to racket.


zenspider
2018-3-16 10:33:59

doesn’t have the bit arithmetic functions, ironically


pocmatos
2018-3-16 10:34:10

that’s right.


zenspider
2018-3-16 10:35:12

before you go off the deep end, read the link in the fixnum doco to the fixnum optimizations in the performance section


zenspider
2018-3-16 10:35:30

might be worth it to wrap fixnum with the functionality you don’t have


zenspider
2018-3-16 10:35:35

or at the very least, steal :stuck_out_tongue:


githree
2018-3-16 10:37:17

@pocmatos you may also want to check with @soegaard2 who is the co author of the math library - he is regular at IRC as soegaard


pocmatos
2018-3-16 10:38:05

@zenspider i will take a look


pocmatos
2018-3-16 10:38:20

@githree thanks for the ref.


zenspider
2018-3-16 10:38:30

hrm… looks like it all comes in via '#%flfxnum which, I’m guessing, implies it’s not .rkt but .c


pocmatos
2018-3-16 10:39:48

can’t find the optimization doc you mentioned.


zenspider
2018-3-16 10:39:55

and share/pkgs/r6rs-lib/rnrs/arithmetic/fixnums-6.rkt


zenspider
2018-3-16 10:39:59

that has rotate and some others


zenspider
2018-3-16 10:40:04

no clue as to the speed tho


zenspider
2018-3-16 10:40:13

rnrs/arithmetic/bitwise-6


zenspider
2018-3-16 10:40:14

sec



zenspider
2018-3-16 10:42:39

I’m fading… goodnight all.


pocmatos
2018-3-16 10:43:32

sure, thanks for your help. good night.


pocmatos
2018-3-16 10:43:56

faints after noticing your local time is 3.40am


zenspider
2018-3-16 10:45:04

I told you rosette was just up the street! (I’m in Seattle) :stuck_out_tongue:


ben
2018-3-16 16:22:56

@notjack can you confirm that the number of people using Dart is >= 1 ?


pocmatos
2018-3-16 16:32:42

@ben lol


pocmatos
2018-3-16 16:34:56

Guys, what’s the best way to do a dynamic compile time require? Let’s say I have the path to the directory containing a file to require. During compile time I want to append foo.rkt to the path and require it without incurring the time taken to dynamic require each time I run the file?


pocmatos
2018-3-16 16:35:30

Is this something I can achieve using a macro? Can I require something into the top level with a macro?



pocmatos
2018-3-16 17:00:33

@ben interesting example. Thanks.


samth
2018-3-16 17:06:13

@ben definitely the number of people using dart is >= 10000


ben
2018-3-16 17:10:52

thank you Sam, that settled my argument here with Stephen Chang :)


ben
2018-3-16 17:11:24

he cited Mark Miller ~2012 saying “nobody uses Dart”. The new point of reference is Tobin-Hochstadt ~2018


samth
2018-3-16 17:12:34

I think (a) Dart is more used now (b) Mark probably meant \|Dart users\|/\|JS users\| ~= 0



notjack
2018-3-16 17:36:46

@ben inside Google or outside Google? :P


ben
2018-3-16 17:38:42

yes, either inside or outside


notjack
2018-3-16 17:42:28

there’s still several google projects built on dart AFAIK


ben
2018-3-16 17:43:05

with at least 2 people working on them?


notjack
2018-3-16 17:43:11

yes


ben
2018-3-16 17:43:30

excellent I will tell Stephen


jerome.martin.dev
2018-3-16 17:43:34

Hello there ! Sorry for the newbie question, but this is the first time I try this: I’d like to make a macro with optional keyword arguments. I naively tried this: (define-syntax-rule (define-cascader (name arg ...) #:description [desc #f] #:unless [unless #f] #:fail [fail #f] #:fail-reason [reason #f] body ...) ...yada yada...) but of course, it’s more complicated than that. Is there any shortcuts that would prevent me from spending the next 4 hours reading the syntax-parse doc?


notjack
2018-3-16 17:43:51

@jerome.martin.dev reading the syntax parse docs is probably your best bet


notjack
2018-3-16 17:44:03

there’s a section in the tutorial specifically on how to make optional keyword arguments


jerome.martin.dev
2018-3-16 17:44:10

oh nice


notjack
2018-3-16 17:44:52

jerome.martin.dev
2018-3-16 17:46:33

Thanks :smile:


notjack
2018-3-16 17:46:33

@ben > Dart is an officially approved language for web development in Google3, and is heavily used by the Ads PA.


notjack
2018-3-16 17:47:11

huh looks like there’s even compatibility libraries to use Angular on dart


ben
2018-3-16 17:48:07

thank you all for the help everyone, we’ve convinced Stephen that there are people who use Dart


notjack
2018-3-16 17:48:46

for a second I thought you just said you’d convinced Stephen to use Dart and whoa there, not so fast :p


githree
2018-3-16 17:49:47

@ben are you trying to say it is time to stop procrastinating and start doing something of value :wink: ?


ben
2018-3-16 17:52:28

haha, wishful thinking. It’s phd visit day here (Northeastern) & just starting to get busy


notjack
2018-3-16 17:55:21

Whoa when did dart start getting all this activity? https://medium.com/dartlang/announcing-dart-2-80ba01f43b6


jerome.martin.dev
2018-3-16 18:41:37

Okay, I got my macro working… almost… It is supposed to expand to a lambda form. But when trying to syntax-parse (hello . words) (the lambda dot notation) with the pattern (name arg ...) I get a bad syntax. How do I match usages like (my-macro (count . stuff))?


notjack
2018-3-16 18:42:33

@jerome.martin.dev dotted pairs aren’t matched by elipses


notjack
2018-3-16 18:42:47

(which I find irritating, but alas)


jerome.martin.dev
2018-3-16 18:42:51

Yes x)


notjack
2018-3-16 18:44:10

You have to have another pattern clause which includes the dot, like this:

(syntax-parse stx
  [(_ (name arg ...) body ...) something]
  [(_ (name arg ... . rest-arg) body ...) something])

notjack
2018-3-16 18:44:26

or at least, I don’t know of a better way


jerome.martin.dev
2018-3-16 18:44:38

I see


jerome.martin.dev
2018-3-16 18:46:42

mmmh, maybe a splicing-syntax-class like maybe-rest-arg that would match (~seq #'. rest-args:id)?


ryan565
2018-3-16 18:47:33

@ryan565 has joined the channel


notjack
2018-3-16 18:47:41

the dot isn’t an identifier, it’s reader syntax - the actual AST is differently structured (it’s an improper list of syntax objects instead of a proper list)


jerome.martin.dev
2018-3-16 18:48:01

that’s what I feared…


dedbox
2018-3-16 18:49:59

@ben @notjack Mark Miller? Capabilities? Someone working on/with? Anything worth mentioning?


ben
2018-3-16 18:50:44

nothing worth mentioning, just joking about a conversation from 2012


notjack
2018-3-16 18:51:17

???


jerome.martin.dev
2018-3-16 18:51:53

I always wondered… How do I prevent repeating myself in the something part?


ben
2018-3-16 18:51:54

that’s why I posted about Dart


ben
2018-3-16 18:52:10

“Dart … do people use that”


ben
2018-3-16 18:52:12

“yeah for sure”


ben
2018-3-16 18:52:32

“I dunno, I asked Mark Miller at a conference and he said nobody uses Dart … but that was 2012”


notjack
2018-3-16 18:52:39

oh!


ben
2018-3-16 18:52:45

“ok I’ll ask Jack on slack if at least 1 person uses Dart”


notjack
2018-3-16 18:53:19

¯_(ツ)_/¯


notjack
2018-3-16 18:53:44

making syntax classes so that something is pretty simple is what I usually do for that


jerome.martin.dev
2018-3-16 18:54:59

:cry:


ryan565
2018-3-16 18:55:14

I am new to both Scheme & Racket, but I think I might have stumbled upon a bug in v5.3.6 (which is what my distro provides) Forgive me, because I’m about to do something inane: $ racket Welcome to Racket v5.3.6. > 'x 'x > (define 'x 11) > 'x x: undefined; cannot reference undefined identifier context...: /usr/share/racket/collects/racket/private/misc.rkt:87:7 > (define x 10) > x 10 > 'x 11 I’m not sure that (define 'x 11) is a kosher thing to do. But certainly Racket’s inconsistency in evaluating ’x afterwards can’t be right?


notjack
2018-3-16 18:56:01

'x is reader syntax for (quote x), which is what the macroexpander sees


notjack
2018-3-16 18:57:39

so your example is equivalent to this:

> (quote x)
'x
> (define (quote x) 11)
> (quote x) ;; function call with variable x as argument!
x: undefined
> (define x 10)
> x
10
> (quote x)
11

notjack
2018-3-16 18:58:34

in particular, (define 'x 11) defines a function named quote that shadows the special form quote provided by #lang racket


ryan565
2018-3-16 18:58:47

I follow so far


notjack
2018-3-16 18:59:09

so, not a bug - just really confusing


ryan565
2018-3-16 18:59:30

But why did the last (quote x) change its mind about undefined vs 11 ?


notjack
2018-3-16 18:59:56

because the first quote was referring to the special form quote, but the second one was referring to the function created by (define 'x 11)


ryan565
2018-3-16 18:59:59

Oh — because x is no longer undefined


notjack
2018-3-16 19:00:10

oh whoops I misunderstood your question


notjack
2018-3-16 19:00:11

yes that’s right


ryan565
2018-3-16 19:00:18

Cool, thanks.


notjack
2018-3-16 19:00:48

which distro are you using? 5.3.6 is a few years old I think


notjack
2018-3-16 19:01:02

we’re almost at 7 now :)


notjack
2018-3-16 19:01:14

7.0, that is


ryan565
2018-3-16 19:02:25

My box is Ubuntu 14.04, I’m stuck with what it provides.


ryan565
2018-3-16 19:02:38

We plan to upgrade to 18.04 next month though


githree
2018-3-16 19:13:36

@ryan565 have you considered building racket from source: https://github.com/racket/racket/tree/master/racket/src


jerome.martin.dev
2018-3-16 19:19:50

damn it works but it feels sooo wrooong (syntax-parse stx [(define-cascader (name arg ...) md:maybe-desc mu:maybe-unless mf:maybe-fail body ...) (with-syntax ([proc-head #'(name arg ...)]) (make-pattern stx #'proc-head #'md.desc #'mu.unless #'mf.fail #'mf.reason #'(body ...)))] [(define-cascader (name arg ... . rest-args) md:maybe-desc mu:maybe-unless mf:maybe-fail body ...) (with-syntax ([proc-head #'(name arg ... . rest-args)]) (make-pattern stx #'proc-head #'md.desc #'mu.unless #'mf.fail #'mf.reason #'(body ...)))])


samth
2018-3-16 19:28:03

also there are 6.10 packages for trusty here: https://launchpad.net/~plt/+archive/ubuntu/racket


jerome.martin.dev
2018-3-16 19:32:35

When I have a bunch of syntax objects alive in current scope, let’s say a, b and c, I can directly use them in a #'(a b c) form. But if I want to generate my syntax form with a helper function, I need to pass them all in the arguments, then inside my helper do (quasisyntax/loc stx (#,a #,b #,c)). Is there a better way? Especially for syntax-class instances, which I can’t pass around. Maybe I’m missing something there.


jerome.martin.dev
2018-3-16 19:37:58

May it be that syntax-parse is actually doing that under the hood?


ben
2018-3-16 19:43:26

looks good to me. One alternative is (with-syntax ((a a) (b b) (c c)) (syntax/loc stx (a b c)))


jerome.martin.dev
2018-3-16 19:43:46

Yeah, that’s what I was thinking too


jerome.martin.dev
2018-3-16 19:44:55

I thought I was maybe doing something wild. I guess it’s just the way it is.


jerome.martin.dev
2018-3-16 19:46:44

Thanks for your answers btw :slightly_smiling_face:


jerome.martin.dev
2018-3-16 19:48:11

I’m using racket for about a 6 months now and this is the first time I get to ask questions to knowledgeable people.


jerome.martin.dev
2018-3-16 19:49:40

I need to go so.. see you around!


ryan565
2018-3-16 19:55:28

I occasionally do this sort of thing. But with scheme, I’m so new I don’t think it matters that much for me yet.


ryan565
2018-3-16 19:55:55

Thanks!


notjack
2018-3-16 23:22:35

ah okay! that one I can help with


notjack
2018-3-16 23:23:58
(define-syntax-class proc-head
  (pattern (name arg ...))
  (pattern (name arg ... . rest-args)))

notjack
2018-3-16 23:24:41
(syntax-parse stx
  [(define-cascader head:proc-head md:maybe-desc mu:maybe-unless mf:maybe-fail body ...)
   (make-pattern stx #'head #'md.desc #'mu.unless #'mf.fail #'mf.reason #'(body ...)))])

notjack
2018-3-16 23:26:08

then you can use attributes in the syntax class definition to consolidate logic that depends on whether or not there are rest args


sorawee
2018-3-17 03:19:48

What is the best way to reduce (require ...) time overhead? (lazy-require is not a solution since I do use the required functions)


samth
2018-3-17 03:21:41

@sorawee to require something smaller?


samth
2018-3-17 03:21:53

what file is slow when you require it?


sorawee
2018-3-17 03:27:40

(require racket/string racket/list racket/set racket/bool)


samth
2018-3-17 03:28:51

which one takes a long time?