C function in metaTalk?

xbury.cs at clearstream.com xbury.cs at clearstream.com
Thu Mar 13 08:33:01 EST 2003


Eric,

>   repeat with  i = 0 to the length of s
>       put character 0 to i of s into remainder

There is no character 0 of...
You have to account that C starts its indexes at 0 and MC does it at 1...

I dont thinks that's the whole solution but it's a start ;))

cheers
Xavier


> -----Original Message-----
> From: eric.allen.engle at justice.com 
> [mailto:eric.allen.engle at justice.com]
> Sent: Thursday, March 13, 2003 14:11
> To: metacard at lists.runrev.com
> Subject: C function in metaTalk?
> 
> 
> I'm trying to translate the following C functions into
> hypertalk.
> If done properly they take as input a string, say ABC
> and then 
> permutate it into
> a
> a b
> a b c
> b 
> b c
> c
> 
> UGLY C***************************************
> void permsWithPrefix(string s, string prefix)
> 
> public static void printPerms(String s)
> {
> permsWithPrefix(s, "");
> }
> 
> public static void permsWithPrefix(String s, string
> prefix)
> {
> if (s.length() < 2)
> {
> System.out.println(prefix + s);
> }
> 
> else
> 
> {
> String remainder;
> for (int i = 0; i < s.length(); ++i)
> {
> remainder = s.substring(0,i) + s.substring(i+1);
> permsWithPrefix(remainder, prefix + s.charAt(i));
> }
> }
> }
> 
> The closest I've gotten turning this into hypertalk is:
> 
> 
> 
> SWEET METATALK:*************
> on permswithprefix s, prefix
>   
>   if the length of s < 2 then put prefix & s & return
> after cd fld 1 
> else
>     
>     repeat with  i = 0 to the length of s
>       put character 0 to i of s into remainder
>       put character i+1 of s after remainder
>       permswithprefix remainder, prefix & character i
> of s
>     end repeat
>   end if
>   
> end permswithprefix
> 
> 
> on printperms s
>   permswithprefix s, ""
> end printperms
> 
> 
> 
> 
> on mouseUp
>   printperms abc
> end mouseUp
> 
> 
> *************
> 
> But it still doesn't work, apparently because the
> substring function in 
> c will deliver 1 character(!) if you say
> "eric".substring(2,3) 
> // -- returns r, if I remember correctly
> 
> Any ideas? I would really like to just translate this
> function.
> 
> Thanks!
> 
> My Home Page with free online legal information
> Page perso avec liens juridiques
> 
> http://www.lexnet.bravepages.com/ind.htm
> _________________________________________________
> FindLaw - Free Case Law, Jobs, Library, Community
> http://www.FindLaw.com
> Get your FREE @JUSTICE.COM email!
> http://mail.Justice.com
> _______________________________________________
> metacard mailing list
> metacard at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/metacard
> 


Visit us at http://www.clearstream.com
                                                          
IMPORTANT MESSAGE

Internet communications are not secure and therefore Clearstream International does not accept legal responsibility for the contents of this message.

The information contained in this e-mail is confidential and may be legally privileged. It is intended solely for the addressee. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. Any views expressed in this e-mail are those of the individual sender, except where the sender specifically states them to be the views of Clearstream International or of any of its affiliates or subsidiaries.

END OF DISCLAIMER



More information about the metacard mailing list