Open Side Menu Go to the Top

04-21-2012 , 10:57 AM
Code:
$a =& $b;

$a = &$b;
what is this php tomfoolery? are these lines equivalent?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
04-21-2012 , 01:12 PM
Quote:
Originally Posted by e i pi
Code:
$a =& $b;

$a = &$b;
what is this php tomfoolery? are these lines equivalent?
appear to be:

http://codepad.org/XgApf5Tq

http://codepad.org/Y5WENf4A
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-21-2012 , 04:42 PM
Quote:
Originally Posted by CharlieDontSurf
Question:
"If you were tasked to create a dynamic website (with backend access to a database) that needed to be highly elastic in scalability (potential spikes of 100K+ simultaneous users), what platform (hosting,language,service) would you recommend to use to construct the site?"
AWS for hosting. Language depends on what the use cases for the site are.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-21-2012 , 04:45 PM
Burnss have you read learn you a haskell? (http://learnyouahaskell.com/chapters) I thought this was a really awesome guide to learning the language.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-21-2012 , 04:51 PM
Quote:
Originally Posted by Neko
Haskell is a very tough introduction to programming imo.
I think you are probably right, but I often think that I would be a much better programmer today if the first languages I learned were functional/stateless.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-21-2012 , 06:26 PM
+1 Learn You A Haskell is great!

You might be right but I just think it's important that a new programmer not get too discouraged and start being able to produce useful programs as soon as possible. That way they will get hooked early and can gradually move on to different paradigms as they progress.

For example, using a for loop is going to be an order of magnitude easier than using recursion for a new programmer to understand.

Code:
evens = []
for x in range(10):
    if x % 2 == 0:
        evens.append(x)

vs

f [] = []
f (x:xs) = if x `mod` 2 == 0 then x : f xs else f xs
It's hard to say though.

BTW Burnss...here's one way to do it with recursion instead of a list comprehension

Code:
Prelude> let { inner input [] = []; inner input (x:xs) =  (count x input, x) : inner input xs}
Prelude> let outer xs =  inner xs (rd0 xs)
Prelude> outer "abcdaabad"
[(4,'a'),(2,'b'),(1,'c'),(2,'d')]
Prelude>
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-21-2012 , 06:27 PM
nah i go to uni and they have all lecture slides but i dont think its been very helpful so will read that link ^^.ty. Its annoying me because i can 'half see the solution' but finding it very difficult to implement

programming cant be much harder then haskell right ha? (i hope )

Last edited by Burnss; 04-21-2012 at 06:34 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-21-2012 , 07:51 PM
this will be the last one, i promise! haha

takes a arguement and a list of lists. if the arguement is in the list, remove it.

sooooo 'b' ["abc", "bc", "aa"] should return ["ac", "ac", "aa"]. Could you tell me why this doesnt work/push me into a direction for me to try figure it out myself with. atm i have...

Code:
f1:: Eq a => a -> [[a]] -> [[a]]
f1 n xs = [f1 n x | x <- xs, x /= n]
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-21-2012 , 11:36 PM
Try breaking up the problem into smaller bits. First write a function:

Code:
f :: Eq a => a -> [a] -> [a]
f a xs = ????
so that

f "b" "aaba" gives "aaa"

Once you've got that working your problem just becomes a matter of applying that function to a list of inputs.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-22-2012 , 01:26 AM
u know.. sometimes s**t happens

http://www.youtube.com/watch?v=uJXOJ6oro_s
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-22-2012 , 09:48 AM
Quote:
Originally Posted by rt1
I think you are probably right, but I often think that I would be a much better programmer today if the first languages I learned were functional/stateless.
Something like Scheme seems superior because it's simpler/less strict than Haskell.

Regarding loops vs recursion: Tbh I don't think loops are inherently easier, if you learn recursion first you'll probably feel it's a lot more natural just like loops feel more natural for me now.
I haven't really used any functional language for anything meaningfull so I'm just speculating.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-22-2012 , 10:36 AM
Quote:
Originally Posted by clowntable
Something like Scheme seems superior because it's simpler/less strict than Haskell.

Regarding loops vs recursion: Tbh I don't think loops are inherently easier, if you learn recursion first you'll probably feel it's a lot more natural just like loops feel more natural for me now.
I haven't really used any functional language for anything meaningfull so I'm just speculating.
I think loops are always a little simpler conceptually than recursion. Loops can be understood with a very simple grasp of how programs work (I linearly go from this point to this point, a variable name X always refers to the same variable). Recursion requires at least some understanding of execution stacks and thinking about how you have multiple versions of every variable X for each instance of the method being called.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-22-2012 , 12:12 PM
i'm with shabby. i've been writing for loops since i was six years old. i don't think six year old tyler_cracker could have wrapped his tiny mammalian brain around recursion.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-22-2012 , 01:12 PM
re loops vs recursion, i definitely feel the same way you guys do, but i'm not convinced it's because loops are inherently simpler than recursion. i think it's fairly likely the feeling is based on 1) familiarity and repetition (see tyler's last comment) and 2) the fact that recursion is rarely taught well.

I imagine it's quite possible to teach young children recursion with the proper tools. Bret Victor came up with this game to teach kids lambda calculus:

http://worrydream.com/#!/AlligatorEggs
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-22-2012 , 01:14 PM
Well recursion is just "split a task into repeatable steps and know when you're done". Conceptually that's pretty easy as well and actually pretty similar to loops except that your shifitng the focus to what the actions/end conditions are and not how often they are repeated (imo).
The dragon story teching recursion from whatever that Lisp book I read it in is pretty good imo

I feel like this should be tested on some people that have never programmed before. Teach half of them recursion and the other half loops and then let them figure out the other one later and see who struggles more or something.

Edit: pretty much what gaming_mouse said
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-22-2012 , 01:33 PM
1. i didn't spend a lot of time thinking it through but i did not find the alligator eggs game to be very clear or enlightening. i can't imagine little me would have felt differently.

2. moar anecdotes: in my first college cs class we used scheme (yay schools with real cs programs!), so we learned recursion first. this was a mind**** for me and others who had never learned functional programming. when we got to iteration a little later, i and others found this more straightforward.

3. i agree that science is the way to truly answer this question. anybody have a class of third graders[1] who want to participate in an experiment?

Last edited by tyler_cracker; 04-22-2012 at 01:35 PM. Reason: [1] er, sorry euros. 8-9 year olds.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-22-2012 , 03:10 PM
Quote:
Originally Posted by tyler_cracker
1. i didn't spend a lot of time thinking it through but i did not find the alligator eggs game to be very clear or enlightening. i can't imagine little me would have felt differently.
guess it wasn't clear, but that alligator game wasn't meant to teach recursion. it's meant to teach lambda calculus, arguably much more complex -- it was just a cool thing i remembered on the subject of teaching kids advanced concepts.

alan kay does a lot of innovative computer teaching with kids -- i wonder if he's done something with recursion.

agree experiments would be needed to answer the original question... i was just proposing learning methods/experience are a confounding factor for most if not all of us.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-22-2012 , 03:17 PM
Is recursion more intuitive for something like the fibonacci numbers that we naturally define inductively?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-22-2012 , 03:28 PM
Quote:
Originally Posted by NoahSD
Is recursion more intuitive for something like the fibonacci numbers that we naturally define inductively?
yeah i'd think so
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-22-2012 , 03:56 PM
If it wasn't clear, I meant more intuitive than a for loop.

I mean.. to someone who doesn't know programming at all, which function is more clear:

Code:
fib(n)
{

if (n == 0) return 1
if (n == 1) return 1
return fib(n-1) + fib(n-2)

}
or

Code:
fib(n)
{

first = 1
second = 1

for count in range(n-1)
{

temp = first + second
first = second
second = temp

}

return second
}
(I was lazy and didn't bother to handle the one or zero cases elegantly since this happens to work as long as range(0) and range(-1) are empty.)


I mean.. the second seems much less intuitive to me, but recursion was pretty weird the first time I saw it IIRC.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-22-2012 , 04:02 PM
Any time when someone will say this? "This problem can be solved with recursion but not loops." or "This problem is better solved with recursion than loops." Because I always use loops maybe I should use both?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-22-2012 , 04:02 PM
is it better to do recursion or loops? I assume loops are quicker at runtime?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-22-2012 , 04:10 PM
about recursive algorithms.... there are some algoriths that is better do them with loops and others with recursion

like the fibonnaci algorithm, if u implement it with a recursive algorithm its way slower than with loops
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-22-2012 , 04:17 PM
Quote:
Originally Posted by NoahSD
If it wasn't clear, I meant more intuitive than a for loop.

I mean.. to someone who doesn't know programming at all, which function is more clear:

Code:
fib(n)
{

if (n == 0) return 1
if (n == 1) return 1
return fib(n-1) + fib(n-2)

}
or

Code:
fib(n)
{

first = 1
second = 1

for count in range(n-1)
{

temp = first + second
first = second
second = temp

}

return second
}
(I was lazy and didn't bother to handle the one or zero cases elegantly since this happens to work as long as range(0) and range(-1) are empty.)


I mean.. the second seems much less intuitive to me, but recursion was pretty weird the first time I saw it IIRC.
hmm... that's tougher to answer. honestly someone with no programming experience would find both confusing, and probably any possible code confusing.

conceptually, i think the "pure" recursion of the first is not natural... an iterative recursion would be more natural. if you had to explain the fib numbers to a total non-mathemetician, you would do constructively, i think, writing out 1, 1 ("now you just add these and write down the answer") 2, ("now you add the new one and the last one"), etc...

this is closer to the for loop you wrote, but there is an iterative version of the recursive function which has three arguments (last two fib numbers, and a counter which acts as your stopping point) -- i think that would be closest of all to the natural explanation.

EDIT: better yet, use infinite sequence from python or ruby:

Code:
def fib():
    a, b = 0, 1
    while 1:
        yield a
        a, b = b, a + b
 
fibo = fib()
for x in range(100):
    print fibo.next(),

Last edited by gaming_mouse; 04-22-2012 at 04:23 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

      
m