Post Reply 
what is a string?
12-12-2013, 03:41 PM
Post: #7
RE: what is a string?
Hello,

(12-11-2013 07:11 PM)Alberto Candel Wrote:  Thank you. I was thinking more from the calc point of view. If I had another program nib() that inputs a string of 01's and converts it to a string of -101's, how should I do the composite
nib(bin(13)) so that the quotes are not part of the input?

In your example: nib(bin(13)) 13 is a number (1+1+1...+1 13 times). Numbers are special type of objects in the system which have limitations (12 digits from 0 to 9 for example) and are interpreted in specific ways...

It might be that in your program, whaever you want to do with your input does fit in these limitations. In this case, you can use a number (a real to be exact) and be happy.

It might be that these limitations do block you. In this case, you will need to either change what you are trying to do, or use some other object type to do it.

for example, to represent binary number, you use 0 and 1... but you most likely want to have number with more than 12 digits! therefore, reals are not adapted.
you could use a list of reals (since lists have arbitrary size), but this has some issues. for a start, a list takes a lot of RAM (around 32 bytes per real)... and might not display in a way that suits you.

Since you are unfortunately not at liberty to change how objects get displayed, it pay to use a good match in your objects....

a String, beeing just a sequence of characters is very versatile, fast to use and takes little memory (2 bytes per characters)... so it can work well...
note that you can access (in read and write) characters of a string stored in a variable by doing var(n) where n is the character index (from 1 to string size). This is the fastest way to modify a string.

Cyrille
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
what is a string? - Alberto Candel - 12-11-2013, 06:26 PM
RE: what is a string? - Han - 12-11-2013, 06:46 PM
RE: what is a string? - Alberto Candel - 12-11-2013, 07:11 PM
RE: what is a string? - Han - 12-11-2013, 07:29 PM
RE: what is a string? - cyrille de brébisson - 12-12-2013 03:41 PM
RE: what is a string? - Alberto Candel - 12-11-2013, 10:02 PM
RE: what is a string? - Han - 12-12-2013, 02:51 PM
RE: what is a string? - Alberto Candel - 12-13-2013, 08:27 AM
RE: what is a string? - Han - 12-13-2013, 02:33 PM



User(s) browsing this thread: 2 Guest(s)