123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|117|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> On Topic -> Struggling with recursion

Thu, 27 Aug 2015, 06:17
Afr0
Hi!
I'm taking a programming languages course at uni, and I'm struggling to get my head around recursion. I think it's one of those things that can sometimes be hard to understand, and sometimes easy depending on the context.
I've written the following program in Oz, the language we're using:



This, obviously, returns the larger of the two numbers. The last formula was included in the assignment.

I'm sort of struggling to understand what it does. In the case of 15 and 80, it will return 1 + Max(14, 79), which should be 80. But how does it know this by calling itself? o_O

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Thu, 27 Aug 2015, 06:46
Jayenkai
eeeuw. Not a fan of that language! No separators between important bits. At least shove a comma or two in there!

Origin - Max 4 6
A..1+ max 3 5
B....1+ max 2 4
C......1+ max 1 3
D........0 2. Returns 2
C......1+2 returns 3
B....1+3 returns 4
A..1+4 returns 5
Origin - Returns 6


In all honesty, you wouldn't code something like that. It's horrible and wasteful! But as a learning tool it does indeed help understand what's going on.

-=-=-
''Load, Next List!''
Thu, 27 Aug 2015, 06:58
Afr0
I think the next one is Ada or something.
Anyway, Oz is declarative, so I think that's at least part of the reason. Haven't dealt much with declarative programming before.

Thanks!

Edit: GfK, pretty sure it's not outdated...

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Thu, 27 Aug 2015, 08:04
cyangames
Looks like a pig of a language to use, reminds me of the bizarre Lisp module I had at Uni in my first year many, many moons ago.

Say it with me everybody, "Eurghh LISP....Eurgggghhhhhh" {belches}

-=-=-
Web / Game Dev, occasionally finishes off coding games also!
Thu, 27 Aug 2015, 09:28
Dabz
It does look awful to an experienced programmer, but you can see what it's doing as a program and is very simplistic in its syntax... I can get why they are using it, but if I was sitting in a classroom and they presented that as the working language I would say no, and just build in C++, you know, a language that means something out there in the wild.

Dabz

-=-=-
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 8Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit