|
From: Ethan M. <eam...@gm...> - 2017-08-14 21:47:03
|
>
> Anyhow, implementing basic ascii letters as
> predecessor/successor-system (in a way ``for [ x = "a":"g" ]'' would
> be also nice -- at least looking intuitively in some cases.
I don't like the idea of adding any syntax that depends on ascii encoding.
I would instead suggest a scheme like
gnuplot> array CityNames[25] =
> ["Atlanta","Boston","Charleston","Dallas","Ephrata","Fargo",,,]
> gnuplot> City(letter) = CityNames[
> strstrt("abcdefghijklmnopqrstuvwxyz",letter) ]
> gnuplot> print City("d")
> Dallas
> gnuplot>
That works as shown for ascii a-z but works equally well for non-ascii
gnuplot> GreekCity(letter) = GreekCityNames[
> strstrt("αβγδεζηθικλμνξοπρςστυφχψω", letter) ]
> gnuplot> print GreekCity("β")
> Βούλα
> gnuplot>
>
Ethan
On Mon, Aug 14, 2017 at 7:29 AM, ivana richterova <
iva...@mf...> wrote:
> Hi Ethan,
>
> >> I can disable all syscalls on startup at all. Otherwise I need to
> >> check if there are commands such 'rm -rf /', 'chmod -R a+r ~/.ssh',
>
> > This idea has been raised before.
> > The major problem I see with it is that gnuplot gains a lot of power from
> > being able to filter input and output through pipes.
>
> yes, I know. Pipes are nice and useful, but safe-check of other-hand
> scripts quite annoying. Maybe it would helpful widespread if there are
> strict simple rules for pipes and syscalls which can be demanded
> irrevocably at startup via init-file, as:
>
> - exact list of allowed commands including full path (e.g. /bin/grep,
> /bin/cat) with possibility to define aliases for them (e.g.,
> grep=/bin/grep)
> - do not read or write and access files and directories (except
> executing the allowed commands) outside the current directory tree at
> startup.
> - namely allow file extensions for files that can be (over)written.
> - allow or not creating new subdirs.
> - define permissions for new files and dirs.
>
> >> probably continue development. Currently, on my wish-list there is (1)
> >> a possibility to index arrays by letters OR get ascii code of chars,
> >
> > extension before considering it further. Do you have an example
> > application for which using a character as an array index is a big win?
>
> If I proceed letter-indexed files inside loops, then there are several
> ways how to access filename-related variables.
>
> I'd like, e.g., to fit files Data_<letter>.dat in one loop and used
> the fitted values in another loop.
>
> -------------------------------
> 1, eval, no arrays, so a "classic" way:
> ``
> # filename format: Data_<letter>.dat
> ind(filename) = filename[6:6]
>
> # declare function myvar(x) that decodes myvarX
> cls=' myvar(x)=('
> do for [ i = 1 : 26 ] { cls = sprintf("%s x eq '%c' ? myvar%c :", cls,
> i+96, i+96) }
> cls=cls." 1/0 )
> eval cls
>
> # set all myvarX to NaN
> cls=''
> do for [ i = 1 : 26 ] { cls = sprintf("%s myvar%c = NaN;", cls, i+96) }
> eval cls
>
> # loop1
> do for [ file in files1 ] {
> fit ..... via ____myvar;
> eval "myvar" . ind(file) . " = ____myvar"
> }
>
> # loop2, files2 can differ from files1
> plot for [ file in files2 ] file t sprintf("fit: %.2g", myvar(ind(file)))
>
> # loop3, whole range
> all=''
> do for [ i = 1 : 26 ] { all = sprintf("%s %c", cls, i+96) }
> filename(x)="Data_".x.".dat"
> plot for [ x in all ] filename(x) t sprintf("fit: %.2g", myvar(x))
> ''
> -------------------------------
>
> 2, index an array by associate "internal" varnames ____<letter>____
> for a..z with numbers 1..26:
> ``
> # declare vars ____<letter>____
> cls = ''
> do for [ i = 1 : 26 ] { cls = sprintf("%s ____%c____ = %i;", cls, i+96, i)
> }
> eval cls
> # convert letter to index array (set 1 for "")
> letter2number(c) = ( c eq "" ? 1 : value( "____".c."____") )
> # filename format: Data_<letter>.dat
> ind(filename)=letter2number(filename[6:6])
>
> # set array myvar[26] to NaN
> array myvar[26]
> do for [ i = 1 : 26 ] { myvar[i] = NaN }
>
> # loop1
> do for [ file in files1 ] {
> fit ..... via myvar[ind(file)];
> }
>
> # loop2, files2 can differ from files1
> plot for [ file in files2 ] file t sprintf("fit: %.2g", myvar[ind(file)])
>
> # loop3, whole range
> array all[|myvar|]
> do for [ i = 1 : |all| ] { all[i] = sprintf("%c", i+96) }
> filename(x)="Data_".x.".dat"
> plot for [ i = 1 : |all| ] filename(x = all[i]) t sprintf("fit: %.2g",
> myvar(x))
> ''
> -------------------------------
>
> 3, index arrays via letters:
> # currently not implemented.
>
> ``
> # filename format: Data_<letter>.dat
> ind(filename) = filename[6:6]
>
> # set array myvar["a":"z"] to NaN
> array myvar["a":"z"]
> do for [ x = "a" : "z" ] { myvar[x] = NaN }
>
> # loop1
> do for [ file in files1 ] {
> fit ..... via myvar[ind(file)];
> }
>
> # loop2, files2 can differ from files1
> plot for [ file in files2 ] file t sprintf("fit: %.2g", myvar[ind(file)])
>
> # loop3, whole range
> filename(x)="Data_".x.".dat"
> plot for [ x = "a" : "z" ] filename(x) t sprintf("fit: %.2g", myvar(x))
> ''
> -------------------------------
>
> disclaimer: the example code is not tested so it can miss some bracket etc.
> -------------------------------
>
> As I said I do not miss associative arrays yet, I'd preferred to find
> a way without named letter variables (since they are not universal),
> how to convert basic ascii letters to numbers as well.
>
> Anyhow, implementing basic ascii letters as
> predecessor/successor-system (in a way ``for [ x = "a":"g" ]'' would
> be also nice -- at least looking intuitively in some cases.
>
> Iva
>
|