4

I just started learning a little Scheme, and I'm using Dorai Sitaram's Teach Yourself Scheme in Fixnum Days. In said work it is stated:

Scheme numbers can be integers (eg, 42) ... or complex (2+3i).

Emphasis mine. Note the form.

Using the principles I had been taught so far I tried writing a few different programs that dealt with the different kinds of numbers. I ended up writing this extremely simple snippet to test complex numbers:

(begin
  (display 3+4i)
  (newline)
)

Testing this on codepad.org (which uses MzScheme) and Ideone.com (which uses guile) worked perfectly.

Now, when I tried it with Chicken Scheme (my local development environment), it compiles fine, but when run, crashes and gives me the error:

Error: unbound variable: 3+4i

  Call history:

  main.scm:2: 3+4i      <--

Apperently there's an unbound variable error, but with my limited Scheme I don't even know what that means (yet.)

Has anyone else experienced this? I know Chicken Scheme is supposed to be pretty standards compliant, and so it seems wierd that it wouldn't support something simple like this. I Googled through their documentation, but I couldn't find anything specific (although I think there is an external complex number library available, so perhaps that's a hint.)

If anyone has any suggestions, they'd be greatly appreciated. Thanks in advance! :)

Miguel
  • 1,966
  • 2
  • 18
  • 32

1 Answers1

7

I believe you need to install the numbers extension for dealing with complex numbers in Chicken Scheme. Do this:

> chicken-install numbers

And don't forget to load it:

(use numbers)
Óscar López
  • 232,561
  • 37
  • 312
  • 386
  • I ran `chicken-install numbers`, and it installed fine, but it didn't fix the error. Was this what you meant? :P – Miguel Nov 22 '12 at 03:03
  • Did you load it first? like this: `(use numbers)` – Óscar López Nov 22 '12 at 03:06
  • No I didn't, actually. Anyways, I loaded it in `csi` and it worked! I also added it to the snippet above, but I still get the error? If you don't mind, could you please show how I should rewrite that snippet so that it would work in a compiled environment? – Miguel Nov 22 '12 at 03:43
  • Besides adding `(use numbers)`, I can't think of anything else - it should work by now – Óscar López Nov 22 '12 at 03:48
  • 1
    @Óscar López Can you show a working example that demonstrates usage? – BillRobertson42 Nov 22 '12 at 06:52
  • The OP mentions compiling code. That's probably why it isn't working: the compiler's reader is the simple one from CHICKEN core. There's a [hack to extend the compiler's reader](http://wiki.call-cc.org/eggref/4/numbers#compiled-code), but it has limitations regarding cross-compiled code. Luckily, the upcoming version of CHICKEN, 5, doesn't need these hacks; it has full numeric tower support. – sjamaan Aug 29 '15 at 15:11