Re: matching a simple string variable

2017-01-03 Thread Alexander Burger
Hi Joe,

> >  (match (cons '@A (conc (chop Varstring) '(@B))) ...

> I'm using your "match" here as a simple string matcher. I'm sure there are
> better ways, but I'm happy with my baby steps that appear to work!

If you are only interested in a boolean result, but don't need the values
of '@A' and '@B', you could of course simply do

   (sub? Varstring ...)

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: matching a simple string variable

2017-01-03 Thread Erik Gustafson
Hi Joe,

Also note that it's fairly easy to pull in regex functionality, should you
need it.

See http://rosettacode.org/wiki/Regular_expressions#PicoLisp for an example
(pil64).


Re: matching a simple string variable

2017-01-03 Thread Alexander Burger
On Tue, Jan 03, 2017 at 07:52:34AM +0100, Alexander Burger wrote:
>(match (append '(@A) (chop Varstring) '(@B)) ...

BTW, better is perhaps

   (match (cons '@A (conc (chop Varstring) '(@B))) ...

because 'append' unnecessarily copies the list just built by 'chop'.
'conc' avoids that garbage. Not critical though ;)

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: matching a simple string variable

2017-01-02 Thread Alexander Burger
Hi Bruno,

> If you want
> (match '(@A (chop varstring) @B) description)
> to match
> (match '(@A "C" "I" "T" "Y" @B) description)
> you'll have to add a tilde before chop, like this:
> (match '(@A ~(chop varstring) @B) description)

Yes, but this only works if the value of 'varstring' is constant.


> That said, do you think you could keep "CITY" intact inside the list,
> without cutting it into
> its letters? I mean, would
> (match '(@A "CITY" @B) description)
> work for what you want to do?

No, it matches the symbol "CITY". Would succeed if you call

   (match '(@A "CITY" @B) '("a" "b" "CITY" "c" "d"))

but not

   (match '(@A "CITY" @B) '("a" "b" "C" "I" "T" "Y" "c" "d"))


> Because if it does, then you can write:
>   (setq varstring "CITY")
>   (match '(@A varstring @B) description)
> which is much simpler than the first solution I gave.

No, this won't work either. As the quoted list is not evaluated, it tries to
match the *atom* 'varstring' which will not be helpful.

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: matching a simple string variable

2017-01-02 Thread Alexander Burger
Hi Joe,

>   (setq varstring "CITY")
>   (match '(@A (chop varstring) @B) description)
> 
> perhaps the function in the middle of the quote is the problem? Or the extra
> list introduced by chop?

Yes. The 'chop' call is not evaluated inside the quoted expression.

There are two ways to handle it:

1. If the string is constant, you can use a read macro

(match '(@A ~(chop "CITY") @B) ...

2. Otherwise you must build the pattern at runtime

   (match (append '(@A) (chop Varstring) '(@B)) ...

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: matching a simple string variable

2017-01-02 Thread Bruno Franco
I think you're right on what's the problem. Chopping the varstring creates
a list of characters,
("C" "I" "T" "Y"), and the final list would look like '(@A ("C" "I" "T"
"Y") @B), which does
not match '(@A "C" "I" "T" "Y" @B) above.

If you want
(match '(@A (chop varstring) @B) description)
to match
(match '(@A "C" "I" "T" "Y" @B) description)
you'll have to add a tilde before chop, like this:
(match '(@A ~(chop varstring) @B) description)

The tilde is a read macro, and it will splice the result into the list. You
can read more about
read macros here: http://software-lab.de/doc/ref.html#macro-io

That said, do you think you could keep "CITY" intact inside the list,
without cutting it into
its letters? I mean, would
(match '(@A "CITY" @B) description)
work for what you want to do?

Because if it does, then you can write:
  (setq varstring "CITY")
  (match '(@A varstring @B) description)
which is much simpler than the first solution I gave.

On Mon, Jan 2, 2017 at 10:52 PM, Joe Golden  wrote:

> I'm trying to do some simple string matching and find match works nicely
> when the string is a literal list of chars like
>
>   (match '(@A "C" "I" "T" "Y" @B) description)
>
> but I need to match on a variable string stored in varstring which then
> needs to get chopped (I think).  I'm running into problems with
>
>   (setq varstring "CITY")
>   (match '(@A (chop varstring) @B) description)
>
> perhaps the function in the middle of the quote is the problem?  Or the
> extra list introduced by chop?
>
> Any guidance appreciated.
> --
> Joe Golden
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>


matching a simple string variable

2017-01-02 Thread Joe Golden

I'm trying to do some simple string matching and find match works nicely when 
the string is a literal list of chars like

  (match '(@A "C" "I" "T" "Y" @B) description)

but I need to match on a variable string stored in varstring which then needs 
to get chopped (I think).  I'm running into problems with

  (setq varstring "CITY")
  (match '(@A (chop varstring) @B) description)

perhaps the function in the middle of the quote is the problem?  Or the extra 
list introduced by chop?

Any guidance appreciated.
--
Joe Golden 
--

UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe