Page 2 of 3 <123>
Topic Options
#73394 - 2003-02-25 04:23 PM Re: RE: arraycomp () UDF by Darren
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Now we get to 18th Hole , eh ?

btw. you missed an line break before 'endfunction' or was this intentional ?
_________________________



Top
#73395 - 2003-02-25 04:38 PM Re: RE: arraycomp () UDF by Darren
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
actually, the line should be:
code:
$s=$s+iif(ascan($1,$)+$m>0 | ascan($1,$)+$m=-1,chr(1)+$,"")

to really be a golf-line [Wink]

[ 25. February 2003, 16:41: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#73396 - 2003-02-25 04:44 PM Re: RE: arraycomp () UDF by Darren
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
no, one more!
code:
$s=$s+iif(ascan($1,$)+$m<>0,chr(1)+$,"")

this one is not tested though [Razz]
_________________________
!

download KiXnet

Top
#73397 - 2003-02-25 04:45 PM Re: RE: arraycomp () UDF by Darren
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Now off for a beer in the club house *sigh !
_________________________



Top
#73398 - 2003-02-25 08:52 PM Re: RE: arraycomp () UDF by Darren
Darren_W Offline
Hey THIS is FUN
*****

Registered: 2001-10-10
Posts: 208
Loc: Bristol, England
Ok...

Tested the last two and they did not work correctly,

Will stick to :

code:
  
function arraycomp($1, $2, optional $m)
dim $
for each $n in $2
if (ascan($1,$n)>-1 and $m) or (ascan($1,$n)=-1 and 0=$m) $=$+chr(1)+$n endif
next
$arraycomp=split(substr($,2),chr(1))
endfunction

Which works great...

Thanks for your work, lets hope it will come in useful.
_________________________
I want to share something with you - the three sentences that will get you through life.
Number 1, 'cover for me.'
Number 2, 'oh, good idea, boss.'
Number 3, 'it was like that when I got here'.

Top
#73399 - 2003-02-25 08:54 PM Re: RE: arraycomp () UDF by Darren
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You're not DIMming your variables correctly. Please code with the restricive settings of OPTION('Explicit','on') and OPTION('NoVarsInStrings','on')
_________________________
There are two types of vessels, submarines and targets.

Top
#73400 - 2003-02-25 08:56 PM Re: RE: arraycomp () UDF by Darren
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
darren, I quess it was that iif-stuff.

it does not always work the same way one would think.

anyway, could you try your current code with changing of:
code:
if (ascan($1,$n)>-1 and $m) or (ascan($1,$n)=-1 and 0=$m) $=$+chr(1)+$n endif

to:
code:
if ascan($1,$n)+$m<>0 $=$+chr(1)+$n endif

_________________________
!

download KiXnet

Top
#73401 - 2003-02-25 10:19 PM Re: RE: arraycomp () UDF by Darren
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Jens,

NoVarsInStrings SUCK BIG TIME [Big Grin]

Just an opinion, nothing personal ... too restrictive no longer intuitive [Smile]
_________________________



Top
#73402 - 2003-02-25 11:21 PM Re: RE: arraycomp () UDF by Darren
Darren_W Offline
Hey THIS is FUN
*****

Registered: 2001-10-10
Posts: 208
Loc: Bristol, England
Example used:

code:
  
$arr1 = a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
$arr2 = 1,2,3,4,f,g,a,34,42,23,c,z,o,r

"results for arraycomp(); elements that don't match:" ? ?
for each $e in arraycomp($arr1, $arr2)
":" $e ?
next
? "results for arraycomp(); matching elements:" ? ?
for each $e in arraycomp($arr1, $arr2, 1)
":" $e ?
next

get $

Result using suggested code:

code:
  
results for arraycomp(); elements that don't match:

:1
:2
:3
:4
:f
:g
:34
:42
:23
:c
:z
:o
:r

results for arraycomp(); matching elements:

:f
:g
:a
:c
:z
:o
:r

Using Present:

code:
 
results for arraycomp(); elements that don't match:

:1
:2
:3
:4
:34
:42
:23

results for arraycomp(); matching elements:

:f
:g
:a
:c
:z
:o
:r


I've tested this a few times and this is the results I get?

[ 25. February 2003, 23:22: Message edited by: Darren ]
_________________________
I want to share something with you - the three sentences that will get you through life.
Number 1, 'cover for me.'
Number 2, 'oh, good idea, boss.'
Number 3, 'it was like that when I got here'.

Top
#73403 - 2003-02-26 07:55 AM Re: RE: arraycomp () UDF by Darren
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Thats correct ...

as this evaluates true for non-matching mode as well if ascan returns > 1 (not zero) therfore the element 0 is not returend but all else

Talked to Jooel yesterday and we agreed to sleep it over and see what we can do today [Wink]
_________________________



Top
#73404 - 2003-02-26 08:41 AM Re: RE: arraycomp () UDF by Darren
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
mm...
taking it back one step:
code:
if ascan($1,$n)+$m<0 | (ascan($1,$n) & $m) $=$+chr(1)+$n endif 

looks pretty long... too long.
_________________________
!

download KiXnet

Top
#73405 - 2003-02-26 10:27 AM Re: RE: arraycomp () UDF by Darren
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
plus ... it did not work as well ....

Dunno if it is a different line pasted into another udf (still not enough coffee to start) but this is the result :

quote:
results for arraycomp(); elements that doesn't match:
----------
1
2
3
4
34
42
23
----------

results for arraycomp(); matching elements:
----------
1
2
3
4
f
34
42
23
z
r
----------

_________________________



Top
#73406 - 2003-02-26 10:54 AM Re: RE: arraycomp () UDF by Darren
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
so going back more (just drank some coffee)...

this?
code:
 if (ascan($1,$n)>-1 and $m) or ascan($1,$n)+$m<0 $=$+chr(1)+$n endif

I even left the AND and OR keywords there...

going for smoke, trying later.
_________________________
!

download KiXnet

Top
#73407 - 2003-02-26 11:25 AM Re: RE: arraycomp () UDF by Darren
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Now that looks quite ok ...

will test deeper but predict a 100% waterproofness [Big Grin]
_________________________



Top
#73408 - 2003-02-26 11:28 AM Re: RE: arraycomp () UDF by Darren
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
think we have a winner :



break on

$arr1 = a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
$arr2 = 1,2,3,4,f,g,a,34,42,23,c,z,o,r


"results for arraycomp(); elements that doesn't match:" ?
"----------"?
for each $e in arraycomp($arr1$arr2)
    $e ?
next
"----------" ?

"results for arraycomp(); matching elements:" ?
"----------" ?
for each $e in arraycomp($arr1$arr21)
    $e ?
next
"----------"?

get $


function arraycomp($1$2optional $m)
    dim $
    for each $n in $2
        if (ascan($1,$n)>-1 and $m) or ascan($1,$n)+$m<0 $=$+chr(1)+$n endif
    next
    $arraycomp = split(substr($,2),chr(1))
endfunction

_________________________



Top
#73409 - 2003-02-26 11:35 AM Re: RE: arraycomp () UDF by Darren
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
that operand color looks nice on grey background...
should we enable tables for postprep?
_________________________
!

download KiXnet

Top
#73410 - 2003-02-26 11:42 AM Re: RE: arraycomp () UDF by Darren
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
k, did some testing and this is the winner:
code:
function arraycomp($1, $2, optional $m)
dim $,$n
for each $ in $2
if (ascan($1,$)>-1&$m)|ascan($1,$)+$m<0 $n=$n+chr(1)+$ endif
next
$arraycomp = split(substr($n,2),chr(1))
endfunction

as you see, you also did not dim the $n...
_________________________
!

download KiXnet

Top
#73411 - 2003-02-26 11:45 AM Re: RE: arraycomp () UDF by Darren
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
we can do that .... think we should take this off-board though

ummm ... well, at least not that this week as I have to prepare my flat for possible purchasers this week after work and I know that I am not that reliable in coding after 14 hrs of work [Frown]

Still there is a family that needs me as well etc. etc.

So, I'll try to get time but can't promise anything
_________________________



Top
#73412 - 2003-02-26 11:46 AM Re: RE: arraycomp () UDF by Darren
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
no need to dim a 'for each' var ... IIRC

Any Pitfalls in this ?
_________________________



Top
#73413 - 2003-02-27 12:46 AM Re: RE: arraycomp () UDF by Darren
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
sure it has to be dimmed
otherwise it will use global namespace, no?
_________________________
!

download KiXnet

Top
Page 2 of 3 <123>


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2366 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.264 seconds in which 0.178 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org