
@melisturgul has joined the channel

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!

@trhawes generally, you want to avoid using eval

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

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


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

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

That’s the letter o not zero

ok thank you

I think it stands for “option”

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

that’s good to know

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

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

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?

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

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

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

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

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

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

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

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.

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.

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

I don’t think 7.2 vs. HEAD will matter

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:

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

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


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

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

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

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