No "Done" at end of program in ti basic - ti-basic

Basically, I just want TI basic to not show the "Done" line at the end of the program. How can I do this?
Thanks,

You can do this by writing a blank value at the end of the program:
:ClrHome:"
More details: http://tibasicdev.wikidot.com/cleanup

Related

Ruby code does not run on windows command line

I tried to run this code:
#!/usr/bin/env ruby
class StringSwap
def initialize(str1,str2)
raise Error unless str1.length>4
raise Error unless str2.length>6
temp=str1[3]
str1[3]=str2[5]
str2[5]=temp
#str1=str1
#str2=str2
end
def print()
put str1
put str2
end
end
def main()
puts "WHYYY"
s1=gets().chomp()
s2=gets().chomp()
obj=StringSwap.new(s1,s2)
obj.print()
end
Nothing happens when I type ruby file.rb. It does not give an error but it does not run my program either. When I tried to run scripts like "Hello World" in same way, it worked. Any help would be appreciated
Okay, I was able to solve that by just deleting the main function. Then it worked but I don't know why? Could anybody enlighten me?

Why backspace key deletes the entire row in JRuby and what can be the fix for it?

I have developed a couple of tools in JRuby. Both the tools prompt for few questions to the user. While answering these questions if the user wants to correct a wrong entry and hits backspace key that deletes the entire line (including the question) instead of deleting just one character.
Below is the piece of code that prompts the questions:
require highline/import
def prompt
begin
input=ask("\t\tEnter user name: ") do |ch|
ch=true
end
input
rescue => e
print "Error -"+e
end
end
I was wondering if anyone of you have seen this kind of problem before and what can be the fix for this? Really appreciate your time and help.
Thanks in advance.
Below is the working piece of the code. I removed \t and changed ch=true to ch.readline=true. Thank for all of your help and guidance.
require highline/import
def prompt
begin
input=ask("Enter user name: ") do |ch|
ch.readline=true
end
input
rescue => e
print "Error -"+e
end
end
If you are using highline gem, then when reading the input instead of
input=ask("Enter the Input: "){|ch| ch.echo = true}
use
input=ask("Enter the Input: ") do |ch|
ch.readline=true
end
Source: https://www.ruby-forum.com/topic/4406162

Is it bad practice to not close the file in this snippet?

Just some food for thought about how necessary it is to close the files that I opened explicitly in the code. I came from a background of programming in C and C++, and starting to navigate my way through Ruby. Thanks in advance for your feedback.
from_file, to_file = ARGV
script = $0
puts "Copying from #{from_file} to #{to_file}"
File.open(to_file, 'w').write(File.open(from_file).read())
puts "Alright, all done."
Not closing files is always bad practice unless you are using something like the with statement in python.
While a scripting language will usually close open files on exit, it's cleaner to do it as soon as you are done with the file - especially when writing to it.
Apparently Ruby has something similar to python's with:
File.open(from_file, 'r') do |f_in|
File.open(to_file, 'w') do |f_out|
f_out.write(f_in.read)
end
end
Relevant docs: http://ruby-doc.org/core-1.9.3/File.html#method-c-open
Here's a shorter version:
File.write to_file, File.read(from_file)
This code (Matheus Moreira) closes files automatically:
File.write to_file, File.read(from_file)
There are no ways to close files in this code:
File.open(to_file, 'w').write(File.open(from_file).read())
I guess automatically closing too.
It's a good answer but it's more 'ruby' to put the output file on the outer block and use << :
File.open(to_file, 'w') do |f_out|
f_out << File.open(from_file){|f| f.read}
end
note how you do not need the 'r' when reading.

Run Ruby program until error

Is there a way to make a Ruby program keep executing until the program has an error? I want my loop to stop when the program returns an error.
Thanks
A infinite loop can help?
while true do
your code
end
If your code throw an error the loop stops.
This is another example. Will run infinite times till exception comes and also handles your exception and then exit form code.
inc = 5
while true do
begin
puts 4/inc
inc-=1
rescue Exception=> e
puts e
exit
end
end

How to create an exit message

Is there a one line function call that quits the program and displays a message? I know in Perl it's as simple as:
die("Message goes here")
I'm tired of typing this:
puts "Message goes here"
exit
The abort function does this. For example:
abort("Message goes here")
Note: the abort message will be written to STDERR as opposed to puts which will write to STDOUT.
If you want to denote an actual error in your code, you could raise a RuntimeError exception:
raise RuntimeError, 'Message goes here'
This will print a stacktrace, the type of the exception being raised and the message that you provided. Depending on your users, a stacktrace might be too scary, and the actual message might get lost in the noise. On the other hand, if you die because of an actual error, a stacktrace will give you additional information for debugging.
I got here searching for a way to execute some code whenever the program ends.
Found this:
Kernel.at_exit { puts "sayonara" }
# do whatever
# [...]
# call #exit or #abort or just let the program end
# calling #exit! will skip the call
Called multiple times will register multiple handlers.
I've never heard of such a function, but it would be trivial enough to implement...
def die(msg)
puts msg
exit
end
Then, if this is defined in some .rb file that you include in all your scripts, you are golden.... just because it's not built in doesn't mean you can't do it yourself ;-)

Resources