newLISP Fan Club

Forum => newLISP in the real world => Topic started by: johnd on August 22, 2008, 11:44:53 AM

Title: Regex Question
Post by: johnd on August 22, 2008, 11:44:53 AM
How does newLISP control the value of system variables in regex?  It seems they are set only on non-nil regex results.



> (regex ".*([aeiou]{2}).*" "Seattle")

("Seattle" 0 7 "ea" 1 2)

> $1

"ea"

> (regex ".*([aeiou]{2}).*" "San Francisco")

nil

> $1

"ea"

>



If this is the intended behavior it should probably be documented.  I would argue that nil is a result and that $1 should return nil when the regex evaluates to nil.  This was an issue recently because I was checking for $1 to be nil rather than the regex expression itself.  The regex evaluated to nil but $1 retained a previous value.



John

[/i]
Title:
Post by: cormullion on August 22, 2008, 12:09:23 PM
Is this the same problem as I had?



//http://www.alh.net/newlisp/phpbb/viewtopic.php?t=1948
Title:
Post by: Jeff on August 22, 2008, 12:10:25 PM
I disagree.  I've put that side effect to good use in progressive logic.  You can set $0 yourself between regexes.  And you should always check the return value :)