interesting results from char

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

interesting results from char

Doug Stewart-4
this first part I understand.

>> char [0xbb,0x36]
parse error:

  syntax error

>>> char [0xbb,0x36]
         ^

now for the correct way

>> char ([0xbb,0x36])
ans = �6
>>


now for the interesting results!

>> q= char x=[ 0xbb,0x36]
parse error:

  syntax error

>>> q= char x=[ 0xbb,0x36]
            ^
Ok this is definitely a syntax error


now the unusual result.

 char x=[ 0xbb,0x36]
ans = x=[ 0xbb,0x36]
>> q=ans
q = x=[ 0xbb,0x36]

So why when I try 
q= char x=[ 0xbb,0x36]
it is a syntax error  but
 char x=[ 0xbb,0x36]
is not a syntax error and the ans can be used as a string of "x=[ 0xbb,0x36]"


Just curious!
--
DASCertificate for 206392


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: interesting results from char

Carlo de Falco-2

> On 21 Jun 2017, at 15:17, Doug Stewart <[hidden email]> wrote:
>
> this first part I understand.
>
> >> char [0xbb,0x36]
> parse error:
>
>   syntax error
>
> >>> char [0xbb,0x36]
>          ^
>
> now for the correct way
>
> >> char ([0xbb,0x36])
> ans = �6
> >>
>
>
> now for the interesting results!
>
> >> q= char x=[ 0xbb,0x36]
> parse error:
>
>   syntax error
>
> >>> q= char x=[ 0xbb,0x36]
>             ^
> Ok this is definitely a syntax error
>
>
> now the unusual result.
>
>  char x=[ 0xbb,0x36]
> ans = x=[ 0xbb,0x36]
> >> q=ans
> q = x=[ 0xbb,0x36]
>
> So why when I try
> q= char x=[ 0xbb,0x36]
> it is a syntax error  but
>  char x=[ 0xbb,0x36]
> is not a syntax error and the ans can be used as a string of "x=[ 0xbb,0x36]"
>
>
> Just curious!


I think this is related to the "command form" of Octave functions.
The interpreter parses

 myfunction abcdef

as if you had typed

 myfunction ("abcdef")

therefore

 char x=[ 0xbb,0x36]

is treated as

 char ("x=[ 0xbb,0x36]")

c.



_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: interesting results from char

Doug Stewart-4


On Wed, Jun 21, 2017 at 11:14 AM, Carlo De Falco <[hidden email]> wrote:

> On 21 Jun 2017, at 15:17, Doug Stewart <[hidden email]> wrote:
>
> this first part I understand.
>
> >> char [0xbb,0x36]
> parse error:
>
>   syntax error
>
> >>> char [0xbb,0x36]
>          ^
>
> now for the correct way
>
> >> char ([0xbb,0x36])
> ans = �6
> >>
>
>
> now for the interesting results!
>
> >> q= char x=[ 0xbb,0x36]
> parse error:
>
>   syntax error
>
> >>> q= char x=[ 0xbb,0x36]
>             ^
> Ok this is definitely a syntax error
>
>
> now the unusual result.
>
>  char x=[ 0xbb,0x36]
> ans = x=[ 0xbb,0x36]
> >> q=ans
> q = x=[ 0xbb,0x36]
>
> So why when I try
> q= char x=[ 0xbb,0x36]
> it is a syntax error  but
>  char x=[ 0xbb,0x36]
> is not a syntax error and the ans can be used as a string of "x=[ 0xbb,0x36]"
>
>
> Just curious!


I think this is related to the "command form" of Octave functions.
The interpreter parses

 myfunction abcdef

as if you had typed

 myfunction ("abcdef")

therefore

 char x=[ 0xbb,0x36]

is treated as

 char ("x=[ 0xbb,0x36]")

c.



OK but why cant I do

q = char x = [ 0xbb,0x36]


--
DASCertificate for 206392


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: interesting results from char

Carlo de Falco-2

> On 21 Jun 2017, at 17:22, Doug Stewart <[hidden email]> wrote:
>> On Wed, Jun 21, 2017 at 11:14 AM, Carlo De Falco <[hidden email]> wrote:
>>
>> I think this is related to the "command form" of Octave functions.
>> The interpreter parses
>>
>>  myfunction abcdef
>>
>> as if you had typed
>>
>>  myfunction ("abcdef")
>>
>> therefore
>>
>>  char x=[ 0xbb,0x36]
>>
>> is treated as
>>
>>  char ("x=[ 0xbb,0x36]")
>>
>> c.
>>
>>
>
> OK but why cant I do
>
> q = char x = [ 0xbb,0x36]

IIUC that is because of the "=" sign which leads the interpreter to try and parse that line as an assignment rather than a command.
For example consider the following:

>> disp 0
0
>> disp "0"
0
>> disp 0=
0=
>> disp "0="
0=
>> disp =0
disp = 0
>> disp
disp = 0
>>

c.




_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: interesting results from char

Mike Miller-4
In reply to this post by Doug Stewart-4
On Wed, Jun 21, 2017 at 11:22:04 -0400, Doug Stewart wrote:
> OK but why cant I do
>
> q = char x = [ 0xbb,0x36]

Because command form only works when the "command" is the first word in
the line.

It's the same reason you can do

  which help

but you can't do

  fname = which help

you have to use the functional form

  fname = which ("help")

--
mike

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Loading...