melisturgul
2019-3-1 13:24:53

@melisturgul has joined the channel


trhawes
2019-3-1 14:16:53

I have written a racket program that solves a problem on http://exercism.io\|exercism.io. It is called “meetup”, and the problem it is suppose to solve is to return a date object containing the specific date, given a year month day-of-week and an occurance (i.e. 2019 4 Monday 'first for the first Monday of April 2019 -> return the day of the month)

first, second, third, fourth are all possible occurrences, which are also functions in racket. teenth is the only other possible occurrence (which would just be a day between 12 and 20).

I have the function all-dow-month that returns a list of days (integers) for a given year, month, and day of week, i.e. when I run (all-dow-month 2019 3 'Tuesday) it returns '(5 12 19 26)

From here, I can simply evaluate first, second, third, or fourth on the list. I wrote a custom teenth function to cover that use-case.

The problem I am having is that eval outside of DrRacket (and Emacs racket-mode) does not recognize any of these functions.

My code can be found here: https://github.com/timotheosh/exercism-exercises/blob/master/racket/meetup/meetup.rkt

The tests file here: https://github.com/timotheosh/exercism-exercises/blob/master/racket/meetup/meetup-test.rkt

The error I am getting is raco test: (submod "meetup-test.rkt" test) teenth: unbound identifier; also, no #%top syntax transformer is bound in: teenth context...: do-raise-syntax-error expand-capturing-lifts temp118_0 temp91_0 compile15 temp85_0 /home/thawes/exercism/racket/meetup/meetup.rkt:36:0: meetup-day /usr/share/racket/pkgs/rackunit-lib/rackunit/private/test-suite.rkt:86:13: the-tests /usr/share/racket/pkgs/rackunit-lib/rackunit/private/test-suite.rkt:61:0: apply-test-suite /usr/share/racket/pkgs/rackunit-lib/rackunit/text-ui.rkt:91:0: run-tests5 (submod "/home/thawes/exercism/racket/meetup/meetup-test.rkt" test): [running body] temp37_0 for-loop run-module-instance!125 /usr/share/racket/pkgs/compiler-lib/compiler/commands/test.rkt:179:16 meetup-test.rkt: raco test: test raised an exception

I tried commenting out the tests for teenth, and found that I was getting the same error for first, second, etc.

From what I gathered from the docs, eval used inside a module needs a namespace to reference. It was not at all clear how to give it the intended reference (the file it was called from).

Any help is greatly appreciated!


samth
2019-3-1 14:19:51

@trhawes generally, you want to avoid using eval


samth
2019-3-1 14:20:29

but to solve the particular problem of “the namespace for this file” see define-namespace-anchor and namespace-anchor->namespace


samth
2019-3-1 14:21:14

I would just change your program to use the value first instead of the symbol 'first, and get rid of eval



diego
2019-3-1 14:25:11

@trhawes one additional minor comment in your teenth function: remember that < (and all other comparison functions in Racket) can take more than two arguments. So instead of (and (> x 12) (< x 20)) you can simply say (< 12 x 20)


abmclin
2019-3-1 15:06:41

I’m making the change though to clarify, is the single O a capitalized letter o or a zero?


samth
2019-3-1 15:07:32

That’s the letter o not zero


abmclin
2019-3-1 15:07:42

ok thank you


samth
2019-3-1 15:07:46

I think it stands for “option”


samth
2019-3-1 15:08:10

also I don’t think numerals are allowed in preprocessor definition names


abmclin
2019-3-1 15:09:01

that’s good to know


abmclin
2019-3-1 15:55:37

adding the # define USE_FNDELAY_O_NONBLOCK to the rktio_platform.h file in the 7.2 codebase didn’t resolve the error, am still getting the same socket not connected error when doing raco pkg install


abmclin
2019-3-1 15:56:10

here’s a screenshot of the FreeBSD section in rktio_platform.h


mflatt
2019-3-1 15:57:40

When you run the example with write-byte, what that in a file so that the write-byte was tried immediately? If so, if you sleep for 1 second in between tcp-connect and write-byte, do you still get the same answer?


abmclin
2019-3-1 15:59:15

if I understood your question correctly, no I tried the example in the REPL and manually typed in the lines, and also I had to do (flush-output o) before the error appeared


abmclin
2019-3-1 16:00:21

I’m trying the example again in a file and inserting a sleep line as requested


mflatt
2019-3-1 16:00:53

It seems unlikely that adding a sleep with affect the result, then.


mflatt
2019-3-1 16:02:28

What if you comment out the fcntl(s, F_SETFL, RKTIO_NONBLOCKING); on line 1187 of “rktio_network.c”?


abmclin
2019-3-1 16:03:30

ok, trying that, btw, the file example with the (sleep 1) inserted produced the same error as you expected


abmclin
2019-3-1 16:07:56

it looks like the file in 7.2 is now different from the one in the repo’s HEAD, so I’m switching to the HEAD codebase now


abmclin
2019-3-1 16:08:14

I had been using the 7.2 code from the installers on the website, sorry if that wasn’t clear earlier


trhawes
2019-3-1 16:20:20

Doh! Now that should have been obvious. I’ve been making the same mistake in Common Lisp, and Clojure as well! Thanks for pointing that out.


trhawes
2019-3-1 16:23:36

Thanks for the comments! If this were production code, I would get rid of eval. Since this is a learning exercise, I am just going to rewrite it with hygienicized inputs, and define the needed namespace-anchor.


soegaard2
2019-3-1 16:24:36

The general tip is always to use two arguments with eval. (well - besides only using eval if absolutely necessary)


mflatt
2019-3-1 17:05:47

I don’t think 7.2 vs. HEAD will matter


diego
2019-3-1 17:21:48

I’ve found myself doing the same many times. At least in my brain, I think it’s the decades of using other languages that force two operands per operator :slightly_smiling_face:


abmclin
2019-3-1 17:26:25

I agree, looks like some of difference between 7.2 and HEAD probably don’t matter much, it’s just more of a matter of making sure your line numbers match what I see


abmclin
2019-3-1 17:26:39

so far commenting out line 1187 doesn’t resolve the error


abmclin
2019-3-1 17:26:51

abmclin
2019-3-1 17:27:18

here’s a screenshot of the git diff showing changes made so far and result of ./raco pkg install gregor using the built HEAD


abmclin
2019-3-1 17:27:47

also here’s the defined macros for the OS gcc -dM -E - < /dev/null \| grep FreeBSD #define __FreeBSD__ 13

I checked the defines just in case it was something unexpected


trhawes
2019-3-1 18:00:39

Just to update for posterity’s sake, the code I linked to above is now working. I’ve added a contract to ensure nothing unexpected gets sent to eval (yes, it would be better to just manually handle each case in a cond statement).


mflatt
2019-3-1 21:49:22

I finally installed TrueOS, and now I’ve pushed a change intended to fix this problem