1. How can I combine this into one line of code?

puts(1,"What is ") 
print(1,first_number) 
puts(1," + ") 
print(1,second_number) 
puts(1,"?") 

First_number and second_number are variables for two integers. Thanks.

Edit: Added <eucode> tags. -Greg

new topic     » topic index » view message » categorize

2. Re: How can I combine this into one line of code?

tiger0581 said...

puts(1,"What is ") print(1,first_number) puts(1," + ") print(1,second_number) puts(1,"?") First_number and second_number are variables for two integers. Thanks.

printf(1, "What is %d + %d?", {first_number,second_number} )

See printf for more details.

new topic     » goto parent     » topic index » view message » categorize

3. Re: How can I combine this into one line of code?

tiger0581 said...

puts(1,"What is ") print(1,first_number) puts(1," + ") print(1,second_number) puts(1,"?") First_number and second_number are variables for two integers. Thanks.

-- Version 4 Code 
writef("What is [] + []?", {first_number, second_number}) 
new topic     » goto parent     » topic index » view message » categorize

4. Re: How can I combine this into one line of code?

tiger0581 said...
puts(1,"What is ") 
print(1,first_number) 
puts(1," + ") 
print(1,second_number) 
puts(1,"?") 

First_number and second_number are variables for two integers. Thanks.

I have a habit of doing this:

puts(1, "What is " & sprint(first_number) & " + " & sprint(second_number) & "?") 
new topic     » goto parent     » topic index » view message » categorize

5. Re: How can I combine this into one line of code?

DerekParnell said...
writef("What is [] + []?", {first_number, second_number}) 

Derek, when would one use printf() vs. writef()? Is printf() going to be phased out or does it still have its place?

new topic     » goto parent     » topic index » view message » categorize

6. Re: How can I combine this into one line of code?

euphoric said...
DerekParnell said...
writef("What is [] + []?", {first_number, second_number}) 

Derek, when would one use printf() vs. writef()? Is printf() going to be phased out or does it still have its place?

Good question. printf is not going to go away as far as I can see. The choice as to which one to use will depend on your requirements.

The advantages of writef are...

  • simpler tags. You don't need %s, %d, %f etc just [] for all data types.
  • you can specify the order of the arguments in the tags.
    • writef("[2] follows [1]", {"day, night"}) comes out as "night follows day".
  • There are more output options than printf, eg. binary, octal and hex numbers.
  • The tag syntax is a little more forgiving about how you code it.

The advantage of printf, for now any way, is that it is faster as it is a built-in routine and not a library routine.

We use writef internally in Euphoria for error messages because we need to specify the word order to cater for other languages when messages are translated.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu