Re: JESS: Converting from/to strings
Thank you, that worked! The case in which I am using this is actually more complex than the small example I have shown. I am integrating Jess with the JADE framework. JADE includes an example of how to use Jess, which comes with some code for managing the template of an ACL message (agent stuff). That code is expecting a string in a particular slot, which is why I was trying to convert a certain fact to a string. Otherwise I would have to change the code... May be that is a good thing to do! Henrique [EMAIL PROTECTED] wrote: I think Henrique Lopes Cardoso wrote: (defrule r1 ?x - (foo) = (bind ?string (implode$ ?x)) ;; IS THERE A WAY OF DOING THIS? ?x is a jess.Fact object. You can call any of the methods of jess.Fact on it -- including toString() and toStringWithParens(), one of which surely does what you want. But I think you need to step back a little and look at your design; in particular, the way in which you're structuring your data. For example, why is it important that the foo part of (foo a b c) be including in your string -- since, given the foo pattern, it's already known? Why not just ... ?x - (foo $?data) = (bind ?string (implode $?data)) ... Now, you say that ?string is just going to be passed to a Userfunction implemented in Java. Why not just pass ?data to that Userfunction (or ?x, if that's what you really want?) Why this preprocessing step? Any time you feel like you're fighting Jess (or any tool) to achieve a certain effect, ask yourself if the problem isn't just that the tool is designed to make it easy to do things some other way, and consider if that other way would work for you. - Ernest Friedman-Hill Advanced Software Research Phone: (925) 294-2154 Sandia National LabsFAX: (925) 294-2234 PO Box 969, MS 9012 [EMAIL PROTECTED] Livermore, CA 94550 http://herzberg.ca.sandia.gov To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED] To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED]
Re: JESS: Converting from/to strings
I think Henrique Lopes Cardoso wrote: (defrule r1 ?x - (foo) = (bind ?string (implode$ ?x)) ;; IS THERE A WAY OF DOING THIS? ?x is a jess.Fact object. You can call any of the methods of jess.Fact on it -- including toString() and toStringWithParens(), one of which surely does what you want. But I think you need to step back a little and look at your design; in particular, the way in which you're structuring your data. For example, why is it important that the foo part of (foo a b c) be including in your string -- since, given the foo pattern, it's already known? Why not just ... ?x - (foo $?data) = (bind ?string (implode $?data)) ... Now, you say that ?string is just going to be passed to a Userfunction implemented in Java. Why not just pass ?data to that Userfunction (or ?x, if that's what you really want?) Why this preprocessing step? Any time you feel like you're fighting Jess (or any tool) to achieve a certain effect, ask yourself if the problem isn't just that the tool is designed to make it easy to do things some other way, and consider if that other way would work for you. - Ernest Friedman-Hill Advanced Software Research Phone: (925) 294-2154 Sandia National LabsFAX: (925) 294-2234 PO Box 969, MS 9012 [EMAIL PROTECTED] Livermore, CA 94550 http://herzberg.ca.sandia.gov To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED]
JESS: Converting from/to strings
Hi, I have two problems. --- The first: I have a string which contains an atom. How do I convert it to an atom? I tried this,which works: (bind ?string henrique) (nth$ 1 (explode$ ?string)) Is there a simpler way? --- The second: How do I convert a fact-id into a string? This does NOT work: (bind ?x (assert (this will be a string))) (bind ?string (implode$ ?x)) Jess complains about ?x not being a list. Thank you. Henrique To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED]
Re: JESS: Converting from/to strings
Henrique Lopes Cardoso wrote: Hi, I have two problems. --- The first: I have a string which contains an atom. How do I convert it to an atom? I tried this,which works: (bind ?string henrique) (nth$ 1 (explode$ ?string)) Is there a simpler way? I can't think of any at the moment, maybe someone else has a good technique to share. --- The second: How do I convert a fact-id into a string? This does NOT work: (bind ?x (assert (this will be a string))) (bind ?string (implode$ ?x)) Jess complains about ?x not being a list. The value of ?x will be the result of the (assert) function, which according to the manual here: http://herzberg.ca.sandia.gov/jess/docs/70/functions.html#assert Excerpt: 17.19. (assert fact+) Arguments: One or more facts Returns: A Fact, or FALSE - Facts look like they might be lists but they aren't. In LISP it *would* be because *everything* is a list in LISP ;-D alan Thank you. Henrique To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED] To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED]
Re: JESS: Converting from/to strings
Problem here is that assert does not make a list, it makes a fact with a list: (assert (this will be a string)) this makes ordered template with name this and multislot which is a list (will be a string) to make a list in Jess use create$ (bind ?x (create$ this will be a string)) make ?x variable with value of list (this will be a string) nth will work on it. Dusan Sormaz At 01:44 PM 10/21/2005, you wrote: Hi, I have two problems. --- The first: I have a string which contains an atom. How do I convert it to an atom? I tried this,which works: (bind ?string henrique) (nth$ 1 (explode$ ?string)) Is there a simpler way? --- The second: How do I convert a fact-id into a string? This does NOT work: (bind ?x (assert (this will be a string))) (bind ?string (implode$ ?x)) Jess complains about ?x not being a list. Thank you. Henrique To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED] * * Duan ormaz, PhD, Associate Professor * Ohio University * Industrial and Manufacturing Systems Engineering Department * 277 Stocker Center, Athens, OH 45701-2979 * phone: (740) 593-1545 * fax: (740) 593-0778 * e-mail: [EMAIL PROTECTED] * url: http://www.ent.ohiou.edu/~sormaz *