Post a reply
Username:
Note:If not registered, provide any username. For more comfort, register here.
Subject:
Message body:
Enter your message here, it may contain no more than 60000 characters. 

Smilies
:D :) :( :o :shock: :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen:
Font size:
Font colour
Options:
BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON
Disable BBCode
Disable smilies
Do not automatically parse URLs
Confirmation of post
To prevent automated posts the board requires you to enter a confirmation code. The code is displayed in the image you should see below. If you are visually impaired or cannot otherwise read this code please contact the %sBoard Administrator%s.
Confirmation code:
Enter the code exactly as it appears. All letters are case insensitive, there is no zero.
   

Topic review - reconstruct function foo from string(foo)
Author Message
  Post subject:  Re: reconstruct function foo from string(foo)  Reply with quote
it seems that escaping quotes does not help when applying function construction from string iteratively:
we also have to escape backslashes:

Code:
LIB("findifs.lib");


proc foo ()
{
   string bar = "sdfs";
   return (0);
}
foo;

string fooStr = string(foo);
fooStr;


def fooStrMod = replace(fooStr,"\"","\\\"");

string cmd = "proc bar( )
{
    proc rfoo=\""+fooStrMod+"\";
    return (rfoo());
}";

cmd;
execute (cmd);

bar();


string barStr = string(bar);
barStr;



def barStrMod = replace(barStr,"\\","\\\\");

def barStrMod2 = replace(barStrMod,"\"","\\\"");

cmd = "proc foobar( )
{
    proc rbar=\""+barStrMod2+"\";
    return (rbar()+2);
}";

cmd;
execute (cmd);

foobar();



does the principle of dump differ?

If this isn't gonna work in a generic way (without writing a parser for the Singular language),
the closest approach to compose generator functions without parameters from other functions
would be to introduce intermediate global functions (randomly named):

github.com/Singular/Sources/issues/558
Post Posted: Thu Apr 10, 2014 3:45 pm
  Post subject:  Re: reconstruct function foo from string(foo)  Reply with quote
Your problem can be solved by global search&replace of `"` with `\"` inside `fooStr` before you construct cmd:

Code:
> string fooStr2 = string(fooStr[1..18]) + "\\" + string(fooStr[19..23]) + "\\" + string(fooStr[24..size(fooStr)]);
> fooStr2;


   string bar = \"sdfs\";
   return (0);


;return();

> string cmd = "proc bar( )
. { proc rfoo=\""+fooStr2 +"\";  return (rfoo());
. }"; cmd;

proc bar( )
{ proc rfoo="

   string bar = \"sdfs\";
   return (0);


;return();

";  return (rfoo());
}
> execute (cmd); bar();
0



But since generating a procedure via execute can be very troublesome i would not recommend any of such string manipulations in the Singular interpreter!
Post Posted: Wed Apr 09, 2014 4:34 pm
  Post subject:  Re: reconstruct function foo from string(foo)  Reply with quote
Hello,

I also would like to compose a command to define a function as below:
Code:
proc foo ()
{
   string bar = "sdfs";
   return (0);
}
foo;

string fooStr = string(foo);
fooStr;

string cmd = "proc bar( )
{
    proc rfoo=\""+fooStr+"\";
    return (rfoo());
}";

cmd;
execute (cmd);

bar();

Now it is probably mandatory to escape 'fooStr';
How should this be done?
Post Posted: Tue Apr 01, 2014 10:44 am
  Post subject:  Re: reconstruct function foo from string(foo)  Reply with quote
It should be possible:

Code:
> proc a()
. { return (-666); };
> a();
-666
> string (a);

return (-666);

;return();
> proc A = string (a);
> A();
-666


you can also take a look at dump and getdump, which can store procedures in a text file...
Post Posted: Fri Mar 28, 2014 11:06 am
  Post subject:  reconstruct function foo from string(foo)  Reply with quote
Hello,


is it possible to reconstruct a function from a string?

Code:
proc foo( int param )
{
    return(0);
}
string fooStr = string(foo);
fooStr;
// parameter int param ;
//
//     return(0);
//
//
// ;return();


if yes, is it reliable?

Thanks,

Jack
Post Posted: Thu Mar 27, 2014 8:40 pm


It is currently Fri May 13, 2022 11:02 am
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group