This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
lolmaker2002's profile picture

CCFormat - A simple way to format your current computer

Started by lolmaker2002, 30 November 2016 - 02:56 PM
lolmaker2002 #1
Posted 30 November 2016 - 03:56 PM
this is just a thing i wrote in like 40 mins (with no idea what i was going to make, so i was brainstorming for like an hour),

i also wrote this when i had to go, so i cant add screens or anything, file is in desc

PASTEBIN URL: AaWnayNL

EDIT: this was also a little test for me to see if i could work with tables (never worked with them before, or at least not intensively) and i think it worked out pretty well.
Edited on 30 November 2016 - 05:00 PM
TheRockettek #2
Posted 30 November 2016 - 04:12 PM
Sorry to say this, but cant you just do
shell.run("rm *")
:P/>
AlexDevs #3
Posted 30 November 2016 - 05:46 PM
Spoiler

--CCFormat, made by lolmaker2002
print("THIS PROGRAM WILL COMPLETELY WIPE YOUR DRIVE!")
print("if this action is purposely done, press enter")
print("else, hold CTRL+T")
read()
for k, v in ipairs(fs.list("")) do
  fs.delete(v)
end
Made it better
lolmaker2002 #4
Posted 30 November 2016 - 05:52 PM
Spoiler

--CCFormat, made by lolmaker2002
print("THIS PROGRAM WILL COMPLETELY WIPE YOUR DRIVE!")
print("if this action is purposely done, press enter")
print("else, hold CTRL+T")
read()
for k, v in ipairs(fs.list("")) do
  fs.delete(v)
end
Made it better
thanks! i dont know how the for loop works, so i did the best i could, but if its ok ill use this instead of mine.
EDIT: i've been using computercraft for a long while now but i still dont get half of it, i usually just get lucky with my programs and just roll with it.
Edited on 30 November 2016 - 04:53 PM
lolmaker2002 #5
Posted 30 November 2016 - 06:02 PM
Sorry to say this, but cant you just do
shell.run("rm *")
:P/>
thats true actually, but my goal was to make it so it doesn't remove the file its being executed from, and also to learn how to work with tables.
Sewbacca #6
Posted 06 December 2016 - 03:59 PM
For loops are very important in Lua.
Tazkazz #7
Posted 13 December 2016 - 08:25 PM
For loops are very important in Lua.

In every programming language. *
SquidDev #8
Posted 14 December 2016 - 07:33 AM
For loops are very important in Lua.
In every programming language. *
Not every language. You'd use recursion in functional programming languages instead.
Edited on 14 December 2016 - 12:10 PM
Sewbacca #9
Posted 04 March 2017 - 07:25 PM
For loops are very important in Lua.
In every programming language. *
Not every language. You'd use recursion in functional programming languages instead.
Give an example please.
SquidDev #10
Posted 04 March 2017 - 07:33 PM
Not every language. You'd use recursion in functional programming languages instead.
Give an example please.

For a simple for loop, you could have something like this:

local function printTimes(count, string)
    if count <= 0 then
        return
    else
        print(string)
        return printTimes(count - 1)
    end
end

printTimes(10, "Hello")
This will print the string "Hello" 10 times. This is actually how all loops are implemented in Urn behind the scenes.
Sewbacca #11
Posted 04 March 2017 - 10:40 PM
Not every language. You'd use recursion in functional programming languages instead.
Give an example please.

For a simple for loop, you could have something like this:

local function printTimes(count, string)
	if count <= 0 then
		return
	else
		print(string)
		return printTimes(count - 1)
	end
end

printTimes(10, "Hello")
This will print the string "Hello" 10 times. This is actually how all loops are implemented in Urn behind the scenes.

And which programming languages don't support for loops?
SquidDev #12
Posted 04 March 2017 - 10:50 PM
And which programming languages don't support for loops?
Haskell would be the first to spring to mind: there are no looping constructs at all - you do everything with recursion. Most Lisps won't have loops as part of the core language: they'll be implemented through tail recursion. Generally, a lot of functional programming languages don't have them.