t
2018-8-14 11:02:47

@t has joined the channel


pocmatos
2018-8-14 12:02:27

What’s the best way to send a function through a place? Maybe I don’t need to send the function because the code for the function exists everywhere. I need to tell another place to run a function, so instead of sending the function (which might be hard) I can say, execute function X from module Y. What’s the best way to serialize this?


samth
2018-8-14 13:07:41

@pocmatos the usual approach is a vector with a module path and a symbol, and then use dynamic require on the other end


pocmatos
2018-8-14 13:08:32

@samth Makes sense, thanks. I will try that.


pocmatos
2018-8-14 13:29:24

I have not played much with the graphing capabilities of Racket except to do math plots. Does anyone know how suitable it is to create timelines? (an example of things I am interested: https://github.com/jiahuang/d3-timeline)



redwynskaja
2018-8-14 14:10:27

Racket complains about: ffi-obj: couldn't get "hello" from #<path:/Users/totz/Desktop/eco-playground/libfuncs.dylib> (dlsym(0x60400033eb40, hello): symbol not found). But compiling/running a main.c that uses the “hello” function works. I am trying out the simplest imaginable wrapper: calling a C-function that prints “hello” in Racket.


redwynskaja
2018-8-14 14:16:16

Is there a way to just look into the #<ffi-lib> object to see what it is made of?


redwynskaja
2018-8-14 14:37:40

I am trying to follow this tutorial: https://docs.racket-lang.org/foreign/intro.html#%28part._.Libraries__.C_.Types__and_.Objects%29 . It doesnt complain about missing symbols. But it crashes DrRacket as soon as i call (define win (initscr))


abmclin
2018-8-14 15:59:52

@redwynskaja is main.c being compiled as a library?


abmclin
2018-8-14 16:01:07

oh I see it’s a dylib, did you ensure that hello is being exported by that library?


redwynskaja
2018-8-14 16:01:49

Hm no i think not. However, I found and example in http://github.com/AutoFFI/racket-autoffi\|github.com/AutoFFI/racket-autoffi


redwynskaja
2018-8-14 16:02:20

When using clang according to their example, it works now. (Before I used GCc)


redwynskaja
2018-8-14 16:03:18

So I guess I did it wrong somehow (zero experience). I did not use the Auto ffi tool itself though. Just their library compiling instruction


abmclin
2018-8-14 16:04:14

ok, great! It’s been a while since I used Racket’s ffi, in my experience those type of errors arise due to misconfiguration or missing exports


abmclin
2018-8-14 16:05:23

Not sure why DrRacket crashed when you were following the tutorial, the libcurses might have not been found on your system but didn’t think that would cause DrRacket to crash unless the code in the tutorial was incompatible with the version of libcurses found on your system


abmclin
2018-8-14 16:05:39

that’s the hazard of ffi, you have little protection if something goes awry in that layer


redwynskaja
2018-8-14 16:06:27

Hm couldn’t there be some kind of „box“ in which foreign code runs and at least some message In case of failure?


abmclin
2018-8-14 16:07:35

not necessarily, there’s not much you can do if the DrRacket process gets corrupted. FFI really is low-level, if there’s memory corruption, all bets are off


redwynskaja
2018-8-14 16:14:33

Ah, i understnad


redwynskaja
2018-8-14 16:15:52

I have void hello() { printf("hello\n"); } in my funcs.c file. There seems to be no problem with the FFI except, that calling it in DrRacket REPL doesnt print “hello\n”…


redwynskaja
2018-8-14 16:16:58

However, int add(int a, int b) { return a + b; } works when typing (add 1 2) it prints 3 just fine.


redwynskaja
2018-8-14 16:19:02

It would be great If someone just had a “Sundials” wrapper lying around :slightly_smiling_face: … I’d need years to get there xD


abmclin
2018-8-14 16:23:01

printf is a purely side-effect operation, any strings will be written to the C’s standard output as opposed to being returned to the caller. C’s output doesn’t have to correspond to DrRacket’s output, my guess is additional arrangements have to be made to connect the two


abmclin
2018-8-14 16:23:38

try changing printf("hello\n") to return "hello\n" instead


redwynskaja
2018-8-14 16:34:16

Yes that works. Although it really prints (including " and \n) "hello\n"


leif
2018-8-14 19:30:00

@mflatt These two identifiers have the same binding, but the expander complains that one of them is unbound: https://gist.github.com/LeifAndersen/8c0a8c1722faabad5ee0c04221fc7e98


leif
2018-8-14 19:30:01

leif
2018-8-14 19:30:25

They do seem to have different scope sets, but they ‘seem’ to be resolving to the same identifier.


leif
2018-8-14 21:34:58

@mflatt Hmm…looks like its a Racket 7 bug.


leif
2018-8-14 21:35:09

(because it works in 6.12)


mflatt
2018-8-15 00:14:51

The example works in v6.12, but only because that expander implements a mapping with a questionable choice of keys.

A variant of the example breaks in v6.12. To get the variant, change the end to (define-syntax (f stx) .... #`(list (quote-syntax #,the-x) (quote-syntax x))) (map eval (f)) which illustrates how the MPI on the-x isn’t really the right one to refer to the enclosing module.

The v6.12 expander allows the original example because it uses a resolved module path in a mapping where it should arguably use the MPI as a key. The variant exposes an inconsistency by delaying the use of the resolved module path to a later point, where the “self” MPI must be really a specific MPI for things to work out.


mflatt
2018-8-15 00:16:19

It’s possible that the right solution is a new syntax function that lets you directly construct a binding for a given MPI and symbol (with a given code inspector).


leif
2018-8-15 00:37:41

Ya, that sounds right to me.


leif
2018-8-15 00:37:52

(That’s also what @michael.ballantyne was pushing for earlier today.)


leif
2018-8-15 00:38:17

So, @mflatt, would that be the sort of thing you could easily write, or should I work it out?


mflatt
2018-8-15 01:06:00

I can take a look tomorrow


leif
2018-8-15 01:27:17

Thanks. :slightly_smiling_face:


samth
2018-8-15 02:20:30

That would also let TR stop using code that basically looks like that eval