Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: How to save procedure into a file and run this file nexttime
PostPosted: Sat Aug 28, 2010 3:25 pm 
How to save procedure into a file in singular terminal

After saved, How to run this file next time?

Where will it be saved in Linux such as ubuntu?


Report this post
Top
  
Reply with quote  
 Post subject: Re: How to save procedure into a file and run this file nexttime
PostPosted: Sat Aug 28, 2010 9:44 pm 

Joined: Wed Mar 03, 2010 5:08 pm
Posts: 108
Location: Germany, Münster
Guest wrote:
1.) How to save procedure into a file in singular terminal

2.) After saved, How to run this file next time?

3.) Where will it be saved in Linux such as ubuntu?



I will answer your questions in reversed order.

3.) It will be stored at that place which you indicate.
This means, if you enter
Code:
  write("dummy.sig","string s = \"hello\";s;");

then a file dummy.sig will be stored in that directory
from which you have called Singular.

If you want to store it somewhere else, then use absolute and
relative paths as usual.
Note that the completion with TAB also works here:
This means
Code:

  write("../ 


shows you the directories and from first letters the directory
name will be completeted.

Note that write just appends to an exisiting file, if your
not using > in front of the file name.

For > and >> with write ee my answers in
viewtopic.php?f=10&t=1850

2.) Once you have this file dummy.sig which
contains correct Singular code, then you can bring
it into Singular with <. This will execute its contents.
Code:
> < "dummy.sig";
hello


(The command read will only read the file and return
a string which may be then activated by execute.)

3.) I will explain how to store the procs, but this is not
the recommended solution for developping procedure.

If you have a procedure e.g.
Code:
proc p(int k)
  {
       "Increment your input";
       return(k+1);
  }
p(2);
Increment your input
3

then convert it with the cast string.

write("myproc.sig","proc "+nameof(p) + "(){ " +string(p) + "} ");

Instead nameof(p) you could also just write "proc p( ) "
or give it another name for the proc.

Then
Code:

> kill p;
> p(2);           
   ? `p(2)` is undefined   //   Okay !
   ? error occurred in or before STDIN line 41: `p(2);`

> <"myproc.sig";       // Now it is back again!
> p(2);
Increment your input
3


Now the recommended solution for writing procs.

Develop the procs with an editor, for instance call ESingular
which uses emacs. Then
    * split the window, ESC-x 3
    * open an new file, (if you will not use *scratch*)
    * enable c++-mode (ESC-x c++-mode)
    repeat{
    * develop your proc code
    * save it to some file (e.g. myproc.sig)
    you may also use ESC-x write-region for marked text
    * in the other window bring this code into Singular by
    < "myproc.sig";
    } until your code is OK.


For more advance programming, you may write an whole library,
http://www.singular.uni-kl.de/Manual/la ... .htm#SEC88
which has to be read by LIB

--------
Christian Gorzel


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: How to save procedure into a file and run this file nexttime
PostPosted: Mon Aug 30, 2010 10:35 am 

Joined: Wed Mar 03, 2010 5:08 pm
Posts: 108
Location: Germany, Münster
Forgot to mention:
3.2.5 Editing SINGULAR input files with Emacs
http://www.singular.uni-kl.de/Manual/la ... .htm#SEC36
Quote:
When running ESingular, the C/C++-mode is automatically turned on whenever a file with the suffix .sing, or .lib is loaded.


Furthermore note:

< for file-input ( singular-load-file ) has the key-binding
CTRL-c <
and the LIB command (singular-load-lib) bound to
CTRL-c CTRL-l.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: How to save procedure into a file and run this file nexttime
PostPosted: Mon Sep 06, 2010 3:22 pm 
It works. save as a text file with extension .sing and < "name.sing". Thanks


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

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