Oxygen Basic

Programming => Bugs & Feature Requests => Topic started by: Mike Lobanovsky on November 02, 2014, 01:20:39 AM

Title: [SOLVED] Print Error?
Post by: Mike Lobanovsky on November 02, 2014, 01:20:39 AM
Hi,

Why does this:

Code: [Select]
indexbase 0

sys arr = {
  1,
  2,
  3
}

print arr[0] arr[1] arr[2]

print 6?
Title: Re: Print Error?
Post by: Charles Pegge on November 02, 2014, 01:40:42 AM
Hi Mike,

'+' is Oxygen's default operator

So, to print them as separate numbers, the terms must be interleaved with strings.

tab=chr(9)
print arr[0] tab arr[1] tab arr[2]
Title: Re: Print Error?
Post by: Mike Lobanovsky on November 02, 2014, 02:20:00 AM
:o

Actually I didn't want to print them separately. I actually wanted to print them as 123.

Inscrutable are the ways of God...
Title: Re: Print Error?
Post by: Charles Pegge on November 02, 2014, 02:37:01 AM
You can use empty strings as non-separators  :)

print arr[0] "" arr[1] "" arr[2]

Alternatively, use explicit string conversion with str:

print str(arr[0]) str( arr[1]) str(arr[2])
Title: Re: Print Error?
Post by: Mike Lobanovsky on November 02, 2014, 02:54:59 AM
May I ask what was ideologically wrong with comma separators?
Title: Re: Print Error?
Post by: Charles Pegge on November 02, 2014, 03:22:15 AM
print is a function, like any other in Oxygen. It has no special syntax. The idealogical rule is consistency.
Title: Re: Print Error?
Post by: Peter on November 02, 2014, 03:58:25 AM
Hi,   ;D
Code: [Select]
indexbase 0

sys arr[3] = {1,2,3}
arr = arr[0]*100 + arr[1]*10 + arr[2]
print arr
Title: Re: Print Error?
Post by: Mike Lobanovsky on November 02, 2014, 05:26:42 AM
Charles,

I don't wan't to sound obtrusive or something, but your answer didn't alleviate the issue but rather aggravated it.

So, my question is what was ideologically wrong with print having its arguments separated with commas like any other function of your language? Where is the consistency you're alluding to?

If I'm however asking the wrong kind of question in the wrong place then please simply ignore it.
Title: Re: Print Error?
Post by: Aurel on November 02, 2014, 05:30:42 AM
Quote
'+' is Oxygen's default operator

he he i like it  ;D
Title: Re: Print Error?
Post by: JRS on November 02, 2014, 09:21:44 AM
Code: Script BASIC
  1. arr[0] = 1
  2. arr[1] = 2
  3. arr[2] = 3
  4.  
  5. PRINT arr[0], arr[1], arr[2], "\n"
  6. PRINT arr[0] & arr[1] & arr[2] & "\n"
  7. PRINT arr[0] + arr[1] + arr[2], "\n"
  8.  

Output

jrs@laptop:~/sb/sb22/test$ scriba prtfmt.sb
123
123
6
jrs@laptop:~/sb/sb22/test$

Title: Re: Print Error?
Post by: Charles Pegge on November 02, 2014, 10:55:20 AM
Mike,

Oxygen's core functions are non-variadic, and I think the print function should remain within this group.

Replacing commas with quote-pairs is all that is required to separate numeric expressions in a concatenation. Commas are omitted for all other situations.

Occam's Razor?
Title: Re: Print Error?
Post by: JRS on November 02, 2014, 11:04:07 AM
Quote from: Charles
Oxygen's core functions are non-variadic.

This may be a factor in your migration to C.
Title: [SOLVED] Re: Print Error?
Post by: Mike Lobanovsky on November 02, 2014, 12:38:09 PM
Oxygen's core functions are non-variadic... Occam's Razor?

Thank you, Charles, that's a fair answer. Occam's Razor should be the bedrock of all programming ideologies. :)