1. How can I combine this into one line of code?
- Posted by tiger0581 Oct 05, 2009
- 1225 views
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
2. Re: How can I combine this into one line of code?
- Posted by euphoric (admin) Oct 05, 2009
- 1231 views
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.
3. Re: How can I combine this into one line of code?
- Posted by DerekParnell (admin) Oct 05, 2009
- 1261 views
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})
4. Re: How can I combine this into one line of code?
- Posted by ryanj Oct 05, 2009
- 1224 views
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) & "?")
5. Re: How can I combine this into one line of code?
- Posted by euphoric (admin) Oct 05, 2009
- 1271 views
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?
6. Re: How can I combine this into one line of code?
- Posted by DerekParnell (admin) Oct 05, 2009
- 1465 views
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.