Hi,
some months ago, I asked for a function to make conversion in list. I
needed a function to convert a list like this:
(c1 (p ?x ?y) <- (q ?x ?y) (r ?y ?z))
into this:
(c1 (p (? "x") (? "y")) <- (q (? "x") (? "y")) (r (? "y") (? "z")))
(This is part of a program that does SLD resolution)
In the end the best solution was this function:
(defun replace-?-syms (x)
(typecase x
(symbol
(let ((name (symbol-name x)))
(if (char= (char name 0) #\?)
`(? , (string (char name 1)))
x)))
(cons
(cons (replace-?-syms (car x))
(replace-?-syms (cdr x))))
(t x)))
And it works fine, but now I need to remove quotations of variables (for
example it must appear (? x) instead of (? "x")) so I need that this
function returns
(c1 (p (? x) (? y)) <- (q (? x) (? y)) (r (? y) (? z)))
`(? , (string (char name 1)))
I've tried to remove the "string" part, in `(? , (string (char name 1)))
line, because I need to return only a char, but when I do this lisp
returns (? \#y) instead of (? y)
I'm a bit lost with this, how can I remove the quotations?
thank you very much (again)
On Feb 3, 1:50 pm, javi <·············@hotmail.com> wrote:
> I'm a bit lost with this, how can I remove the quotations?
I'm not sure what the mess you're in is, but do you know about this:
http://cl-cookbook.sourceforge.net/strings.html#symbols
Leslie
javi <·············@hotmail.com> writes:
> some months ago, I asked for a function to make conversion in list. I
> needed a function to convert a list like this:
> [...]
> I've tried to remove the "string" part, in `(? , (string (char name 1)))
> line, because I need to return only a char, but when I do this lisp
> returns (? \#y) instead of (? y)
>
> I'm a bit lost with this, how can I remove the quotations?
So in the mean time you couldn't learn even the most basic lisp stuff
to understand the difference between strings, characters and symbols?
--
__Pascal Bourguignon__ http://www.informatimago.com/
El Sun, 03 Feb 2008 16:01:02 +0100, Pascal Bourguignon escribió:
>
> So in the mean time you couldn't learn even the most basic lisp stuff to
> understand the difference between strings, characters and symbols?
Hi Pascal,
accidentally or not you gave to me the clue, I've googled a way to
convert from string to symbol and I think that "intern" function it's the
solution.
Now the line that returns the conversion from ?x to (? x) looks like this:
`(? , (intern (string (char name 1))))
and it works fine.
Sorry if my questions sound really stupid to you, probably you're right
saying that I should spend more time learning lisp basics but you'll
agree with me if I say that lisp at the beginning it's hard to
understand, and obviously I don't spend all my day with this language.
Anyway thank you very much for the support on this and others topics.
Best regards
On Sun, 03 Feb 2008 16:46:29 +0100, javi wrote:
> Sorry if my questions sound really stupid to you, probably you're right
> saying that I should spend more time learning lisp basics but you'll
> agree with me if I say that lisp at the beginning it's hard to
> understand, and obviously I don't spend all my day with this language.
I find it very difficult to understand that sort of attitude. I see two
possible paths to follow once you've discovered the problem:
Your approach: blindly experiment with different ideas without making any
effort to understand the issue, formulate your question, post it to
c.l.l, wait for Pascal to respond, derive a possible solution from his
cryptic response, google for that solution and blindly insert it into
your code, gaining only a superficial understanding of the problem and
its solution.
OR ....
Spend 5 minutes reading the first parts of even the most basic
introduction to CL and therefore prevent/solve this and 100's of other
such elementary problems.
Not only does the latter solution take less time out of your day for this
one issue, but has the potential to save you thousands of hours by not
needing to follow the former method ever again. It seems quite obvious
what the right thing to do is in this instance.
Cheers,
drewc
--
Posted via a free Usenet account from http://www.teranews.com
P� Sun, 03 Feb 2008 13:50:16 +0100, skrev javi <·············@hotmail.com>:
>
> I've tried to remove the "string" part, in `(? , (string (char name 1)))
> line, because I need to return only a char, but when I do this lisp
> returns (? \#y) instead of (? y)
>
> I'm a bit lost with this, how can I remove the quotations?
>
> thank you very much (again)
>
To make a symbol with the name of a string use intern.
Why limit the name to one character?
use (list (char name 0) (intern (subseq name 1) "KEYWORD")) (untested)
instead
--------------
John Thingstad