[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting (more or less) arbitrary strings to valid variable names

From: Sergei Steshenko
Subject: Re: Converting (more or less) arbitrary strings to valid variable names
Date: Mon, 19 Nov 2012 18:23:01 -0800 (PST)

----- Original Message -----
> From: Bård Skaflestad <address@hidden>
> To: "address@hidden" <address@hidden>
> Cc: 
> Sent: Monday, November 19, 2012 11:47 PM
> Subject: Converting (more or less) arbitrary strings to valid variable names
> All,
> In the long-running thread on "C-equivalent" structure (array) 
> initialisation, someone asked of a way of converting an arbitrary string into 
> a 
> valid variable name.  Unfortunately, I deleted the e-mail too early so I 
> cannot 
> give proper attribution here.
> Still, I may be able to provide at least a partial answer to the inquiry.  
> The 
> built-in function 'genvarname', present since at least Octave 3.2.3,  
> does solve some of this problem.  Here's an example
>     > genvarname ("0  _f00  ba'r")
>     ans = _0___f00__ba_r
> Obviously, the normal restrictions on variable names apply (string restricted 
> to 
> "namelengthmax" characters being the most severe).
> I hope this helps a little bit.
> Sincerely,
> -- 
> Bård Skaflestad
> SINTEF ICT, Applied Mathematics
> _______________________________________________
> Help-octave mailing list
> address@hidden

There is an old Jewish joke.

The joke is a story about a poor Jew who had quite a hard life.

So he, as the tradition prescribes, decided to consult the local rabbi.

The rabbi said: "Buy a goat".

The poor Jew didn't quite understand the essence of the advice, but followed it.


Several months later the poor Jew visited the rabbi again, this time simply 
lamenting and crying about how unbearable his life had become.

The rabbi said: "Sell the goat !".

The poor Jew next day after selling the goat couldn't find enough words of 
gratitude to thank the rabbi. The Jew couldn't belief the relief he found after 
selling the goat.


The problem with your function is that there may already be underscores in 
otherwise illegal name, e.g. 'foo_ _bar'. So, there will be no easy way to get 
back the original name.

A much better way has already been suggested: uuencode -> uudecode - like 
solutions. I.e. reversibility is guaranteed.

But why do we need the "goat" in the first place ?

I went carefully through 
and did _not_ find there "struct arrays". So, this Matlab artifact should be 
implemented in the least obtrusive for end user manner - only to make sure 
Matlab code runs in Octave.

A _consistent_ hash table implementation is fair enough.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]