←  APIs and Utilities

ComputerCraft | Programmable Computers for Minecraft

»

CCFormat - A simple way to format your cur...

lolmaker2002's Photo lolmaker2002 30 Nov 2016

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 by lolmaker2002, 30 November 2016 - 06:00 PM.
Quote

TheRockettek's Photo TheRockettek 30 Nov 2016

Sorry to say this, but cant you just do
shell.run("rm *")
:P
Quote

Ale32bit's Photo Ale32bit 30 Nov 2016

Spoiler
Made it better
Quote

lolmaker2002's Photo lolmaker2002 30 Nov 2016

View PostAle32bit, on 30 November 2016 - 05:46 PM, said:

Spoiler
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 by lolmaker2002, 30 November 2016 - 05:53 PM.
Quote

lolmaker2002's Photo lolmaker2002 30 Nov 2016

View PostTheRockettek, on 30 November 2016 - 04:12 PM, said:

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.
Quote

Sewbacca's Photo Sewbacca 06 Dec 2016

For loops are very important in Lua.
Quote

Tazkazz's Photo Tazkazz 13 Dec 2016

View PostSewbacca, on 06 December 2016 - 03:59 PM, said:

For loops are very important in Lua.

In every programming language. *
Quote

SquidDev's Photo SquidDev 14 Dec 2016

View PostTazkazz, on 13 December 2016 - 08:25 PM, said:

View PostSewbacca, on 06 December 2016 - 03:59 PM, said:

For loops are very important in Lua.
In every programming language. *
Not every language. You'd use recursion in functional programming languages instead.
Edited by SquidDev, 14 December 2016 - 01:10 PM.
Quote

Sewbacca's Photo Sewbacca 04 Mar 2017

View PostSquidDev, on 14 December 2016 - 07:33 AM, said:

View PostTazkazz, on 13 December 2016 - 08:25 PM, said:

View PostSewbacca, on 06 December 2016 - 03:59 PM, said:

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.
Quote

SquidDev's Photo SquidDev 04 Mar 2017

View PostSewbacca, on 04 March 2017 - 07:25 PM, said:

View PostSquidDev, on 14 December 2016 - 07:33 AM, said:

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.
Quote

Sewbacca's Photo Sewbacca 04 Mar 2017

View PostSquidDev, on 04 March 2017 - 07:33 PM, said:

View PostSewbacca, on 04 March 2017 - 07:25 PM, said:

View PostSquidDev, on 14 December 2016 - 07:33 AM, said:

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?
Quote

SquidDev's Photo SquidDev 04 Mar 2017

View PostSewbacca, on 04 March 2017 - 10:40 PM, said:

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.
Quote