Author Topic: [SOLVED] Print Error?  (Read 4453 times)

0 Members and 1 Guest are viewing this topic.

Mike Lobanovsky

  • Guest
[SOLVED] Print Error?
« 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?
« Last Edit: November 02, 2014, 12:40:06 PM by Mike Lobanovsky »

Charles Pegge

  • Guest
Re: Print Error?
« Reply #1 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]

Mike Lobanovsky

  • Guest
Re: Print Error?
« Reply #2 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...

Charles Pegge

  • Guest
Re: Print Error?
« Reply #3 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])

Mike Lobanovsky

  • Guest
Re: Print Error?
« Reply #4 on: November 02, 2014, 02:54:59 AM »
May I ask what was ideologically wrong with comma separators?

Charles Pegge

  • Guest
Re: Print Error?
« Reply #5 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.

Peter

  • Guest
Re: Print Error?
« Reply #6 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
« Last Edit: November 02, 2014, 04:24:55 AM by Peter »

Mike Lobanovsky

  • Guest
Re: Print Error?
« Reply #7 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.

Aurel

  • Guest
Re: Print Error?
« Reply #8 on: November 02, 2014, 05:30:42 AM »
Quote
'+' is Oxygen's default operator

he he i like it  ;D

JRS

  • Guest
Re: Print Error?
« Reply #9 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$


Charles Pegge

  • Guest
Re: Print Error?
« Reply #10 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?

JRS

  • Guest
Re: Print Error?
« Reply #11 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.

Mike Lobanovsky

  • Guest
[SOLVED] Re: Print Error?
« Reply #12 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. :)