
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?

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

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

@zenspider why would there be two of me?

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:

@pmatos vs @pocmatos

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

thanks.

what are you trying to do anyways?

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.

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

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

ok :slightly_smiling_face:

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

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

wow. they name the functions terribly on the rosette side

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

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

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

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.

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

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.

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

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

for unsigned bitvector 32 arithmetic.

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

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:

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.

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

yes, i reached the same conclusion.

have you seen racket/fixnum and unsafe-fixnum?

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

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

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

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

doesn’t have the bit arithmetic functions, ironically

that’s right.

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

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

or at the very least, steal :stuck_out_tongue:

@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

@zenspider i will take a look

@githree thanks for the ref.

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

can’t find the optimization doc you mentioned.

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

that has rotate and some others

no clue as to the speed tho

rnrs/arithmetic/bitwise-6

sec


I’m fading… goodnight all.

sure, thanks for your help. good night.

faints after noticing your local time is 3.40am

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

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

@ben lol

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?

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

yep a macro can expand to a require: http://docs.racket-lang.org/syntax-parse-example/index.html?q=conditional-require#%28part._conditional-require%29

@ben interesting example. Thanks.

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

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

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

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


@ben inside Google or outside Google? :P

yes, either inside or outside

there’s still several google projects built on dart AFAIK

with at least 2 people working on them?

yes

excellent I will tell Stephen

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?

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

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

oh nice

See the Examples section: http://docs.racket-lang.org/syntax/stxparse-examples.html?q=syntax%2Fparse

Thanks :smile:

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

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

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

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

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

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

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

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

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

(which I find irritating, but alas)

Yes x)

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

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

I see

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

@ryan565 has joined the channel

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)

that’s what I feared…

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

nothing worth mentioning, just joking about a conversation from 2012

???

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

that’s why I posted about Dart

“Dart … do people use that”

“yeah for sure”

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

oh!

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

¯_(ツ)_/¯

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

:cry:

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?

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

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

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

I follow so far

so, not a bug - just really confusing

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

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)

Oh — because x
is no longer undefined

oh whoops I misunderstood your question

yes that’s right

Cool, thanks.

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

we’re almost at 7 now :)

7.0, that is

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

We plan to upgrade to 18.04 next month though

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

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

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

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.

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

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

Yeah, that’s what I was thinking too

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

Thanks for your answers btw :slightly_smiling_face:

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

I need to go so.. see you around!

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.

Thanks!

ah okay! that one I can help with

(define-syntax-class proc-head
(pattern (name arg ...))
(pattern (name arg ... . rest-args)))

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

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

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

@sorawee to require
something smaller?

what file is slow when you require
it?

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

which one takes a long time?