AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

Does substitute delete words?
 
 

I have the following macro using substitute and am not sure why I’m losing words in the variable:

outputmacro: ^reverse(^arg)
reverse ^arg \n
^arg = substitute(WORD ^arg I you)
^arg = substitute(WORD ^arg am are)
^arg = substitute(WORD ^arg was were)
^arg = substitute(WORD ^arg my your)
^arg = substitute(WORD ^arg me you)
arg is ^arg \n

My output is:
reverse I am going to kill myself
arg is self

 

 
  [ # 1 ]

Nobody? It seems “myself” is the word that is screwing up this output but I dont understand why. I even tried turning of interjection splitting and substitute system with no luck. :prepare does not show any changes to the input. In any case ^arg is receiving the string okay and it is only being reduced to “self” after the substitutes.

 

 
  [ # 2 ]

Further investigation reveals the words are being deleted after the “my your” substitute. If I put a “myself yourself” substitute before that the script works fine but I don’t know WHAT the problem was.

 

 
  [ # 3 ]

I was away… Backing up… what you tried to do was perfectly reasonable, just currently illegal. I will probably allow it in a future version soon.  You cannot ASSIGN to a function argument. So the contents of your macro doesnt work as you expect and CS doesnt warn you.

Function arguments are pass by name, not pass by value.  Not documented. Not explained. Try using $$tmp variables inside your macro

 

 
  [ # 4 ]

Thanks Bruce. Using $$vars and eval() worked. I think I needed eval because the arg was a variable and simply assigning $$tmp = ^arg was saving $$tmp as ^arg and not its evaluated value.
Is there any way I can output something in a function(macro) as debugging text but not have it output as part of the function?

 

 
  [ # 5 ]

Sorry I retried without eval on one substitute and it worked. Not so for multiple substitutes. Strange. Must have something to do with how CS currently handles arg assignments. Any hints about the debugging question?

 

 
  [ # 6 ]

you could use the ^log function or the ^eval( :log whatver)

 

 
  [ # 7 ]

I am still having issues with substitute. Here is my current script:
outputmacro: ^reverse(^arg)
$$tmp = eval(^arg)
$$out = $$tmp
$$out = substitute(WORD $$out I you)
$$out = substitute(WORD $$out am are)
$$out = substitute(WORD $$out was were)
$$out = substitute(WORD $$out myself yourself)
$$out = substitute(WORD $$out my your)
$$out = substitute(WORD $$out me you)
$$out\n

It is being called like this:
$out = join(‘_1 _ ‘_2)
$out = ^reverse($out)
Out is $out \n

The rule pattern is :
a: (_~emotions * [which that] * me * _{~verbs}  _*)

For $out that contains the substitute oldtext as words it works fine. But when oldtext is embedded in a word it returns a null string upto the embedded word in $out. I am assuming that $out and $$out are two seperate variables.
By embedded in words I mean:
name—> am is embedded, returns e
wasted—> was is embedded, returns ted

 

 
  [ # 8 ]

It would be easier for me to understand if you gave sample inputs.

I would not put \n on the last line of the macro, you want to return the switched word stream, and you put \n on the Out is $out also.

I would just do $$out = ^arg   and skip $$out = $$tmp

outputmacro: ^reverse(^arg)
$$out = ^arg
$$out = substitute(WORD $$out I you)
$$out = substitute(WORD $$out am are)
$$out = substitute(WORD $$out was were)
$$out = substitute(WORD $$out myself yourself)
$$out = substitute(WORD $$out my your)
$$out = substitute(WORD $$out me you)
$$out

I could have done
$$out = substitute(WORD ^arg I you) and skipped the first assignment
$

My rule was:  u: (_*)  $out = ^reverse(‘_0)  Out is $out \n
My input was “my name is where I live” and my output was “your name is where you live”

 

 
  [ # 9 ]

Actually Bruce I think it was a version issue. I was using 5.4 and I think it now works with 5.92. Even your new script didnt work with the old version. I’ll keep trying some other inputs and get back to you if I find something. Thanks.

 

 
  login or register to react