A lisp oriented question - interning symbols for use in Maxima
Subject: A lisp oriented question - interning symbols for use in Maxima
From: Dieter Kaiser
Date: Sun, 18 Oct 2009 22:13:11 +0200
Am Sonntag, den 18.10.2009, 19:12 +0200 schrieb ?iga Lenar?i?:
> Hi!
>
> I'm writing a Maxima interface to CFFI (for using C libraries from
> Maxima).
>
> I have the following problem - I want to convert a lisp string into a
> symbol representing a Maxima function which would be invoked by the
> same 'string' from Maxima console.
>
> Right now I use
>
> (intern (concatenate 'string "$" string))
>
> to get the symbol which should represent the maxima function.
>
> I get the correct results for cases such as "HelloWorld" -> |
> $HelloWorld| (then the function can be called from maxima with
> 'HelloWorld()').
>
> However if I try non-mixed case strings I get an inverted result. So
> a string like "mul2" gives me a symbol |$MUL2|, which from Maxima is
> seen as 'MUL2' and not 'mul2' as I would want it to be.
>
> What should I do to get the correct lisp symbol, so calling from
> Maxima will look like the string I use?
>
> Are there already any functions in Maxima I should use or how should
> I roll my own?
>
>
> On a side note, is there any interest for a foreign library interface
> in Maxima? Of course it works only in CFFI supported lisps, so no GCL
> support, sorry. I quickly compared the calling overhead by importing
> the C function 'rand()' from 'libc' and compared it to Maxima's
> function 'random' - calling C function from Maxima was faster, so I
> guess the overhead is quite small (on SBCL at least).
The functions which handle Maxima's convention of inverting strings are:
maybe-invert-string-case
intern-invert-case
print-invert-case
maybe-invert-string-case accepts a string and returns a string, which is
inverted, if all characters are upper case or lower case.
Examples:
(maybe-invert-string-case "example") --> "EXAMPLE"
(maybe-invert-string-case "EXAMPLE") --> "example"
(maybe-invert-string-case "Example") --> "Example"
intern-invert-case accepts strings too, but interns the converted string
in the package :maxima. This function is equivalent to
(intern (maybe-invert-string-case str))
Examples:
(intern-invert-case "text") --> TEXT :INTERNAL
(intern-invert-case "TEXT") --> |text| NIL
(intern-invert-case "Text") --> |Text| NIL
print-invert-case accepts symbols as input and returns an inverted
string. The routines accepts strings and any other printable values too,
but returns strings unchanged.
Examples:
(print-invert-case 'text) --> "text"
(print-invert-case '|text| --> "TEXT"
(print-invert-case "TEXT" --> "TEXT"
(print-invert-case 10.0) --> "10.0"
Dieter Kaiser