Thanks, It's what I need, but, I need to implement this behaviour in JESS 6.1, and "for" function it's not present... this is my problem. How can I implement this using only JESS 6.1 features?
------------------------------------------------------------------------ Antonino Lo Bue Research Fellow ICAR-CNR Palermo Phone: 091-6809256 Web: http://medialab.pa.icar.cnr.it/Personali/personali.html Email: [EMAIL PROTECTED] ----- Original Message ----- From: "Ernest Friedman-Hill" <[EMAIL PROTECTED]> To: <[email protected]> Sent: Thursday, January 11, 2007 1:45 PM Subject: Re: JESS: list duplicate elements problem > All you're trying to do is print the integers from 1 to the length of > the list. Here's a "for" loop that does that: > > (for (bind ?i 1) (<= ?i (length$ ?*a*)) (++ ?i) > (printout t ?i crlf)) > > Because your solution has to search the list, for long lists, the > performance would be rather bad, proportional to the square of the > length of the list. Presumably you want to do something with the list > items; you can do so by fetching each one inside the loop with the > "nth$" function, using ?i for the index. For example, this prints > only the indexes at which "bb" appears in the list: > > (for (bind ?i 1) (<= ?i (length$ ?*a*)) (++ ?i) > (bind ?item (nth$ ?i ?*a*)) > (if (eq ?item bb) then > (printout t ?i crlf))) > > > > > On Jan 11, 2007, at 7:10 AM, Antonino Lo Bue (gmail) wrote: > > > Hi everyone, > > I've problems with list members position: > > > > (defglobal ?*a* = (create$ aa aa)) > > thus I have the list: (aa aa) > > > > I want to use member position, but if I write: > > > > (foreach ?f ?*a* (printout t (member$ ?f ?*a*)crlf )) > > > > I obtain: > > 1 > > 1 > > > > Otherwise I want: > > 1 > > 2 > > > > This problem is because member$ function find the index of a > > element in list if this element exist in the list, thus if the > > element is duplicate in the list member$ function find the first > > element two times in the same position. > > > > How can I obtain the position of an element in the list even if is > > a duplicate? > > > > ---------------------------------------------------------------------- > > -- > > Antonino Lo Bue > > Research Fellow > > ICAR-CNR Palermo > > Phone: 091-6809256 > > Web: http://medialab.pa.icar.cnr.it/Personali/personali.html > > Email: [EMAIL PROTECTED] > > > > > > --------------------------------------------------------- > Ernest Friedman-Hill > Advanced Software Research Phone: (925) 294-2154 > Sandia National Labs FAX: (925) 294-2234 > PO Box 969, MS 9012 [EMAIL PROTECTED] > Livermore, CA 94550 http://www.jessrules.com > > -------------------------------------------------------------------- > 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] --------------------------------------------------------------------
