YouTube

Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← 03-29 Changing Functions

dummy description

Get Embed Code
1 Language

Showing Revision 1 created 04/29/2012 by Amara Bot.

  1. Let's go about implementing that.
  2. Let's say I had my old definition of sequence of (x,y),
  3. and we say return the tuple consisting of a sequence x and y.
  4. Now I want to change that. How would I change that?
  5. Well, instead of x and y, I think I'm going to insist that we have at least 1 argument,
  6. so I can say x and then the rest of the args,
  7. and I can say, if the length of the rest of the args equals 1,
  8. then I've got this binary case and then I can take sequence of x.
  9. The second arg is now no longer called y.
  10. It's called args at 0.
  11. Else: now I've got a recursive case with more than 2 args, and I can do something there.
  12. So it's not that hard, but I had to do a lot of violence to this definition of sequence,
  13. and come to think of it, I may be repeating myself because I had to do this for sequence,
  14. and I'm also going to have to do it for alt,
  15. and if I expand my program, let's say I start wanting to take on arithmetic
  16. as well as regular expressions, then I may have functions for addition and multiplication
  17. and others, and I'm going to have to make exactly the same changes
  18. to all these binary functions.
  19. So that seems to violate the "Don't Repeat Yourself" principle.
  20. I'm making the same changes over and over again.
  21. It's more work for me. There's a possibility of introducing bugs.
  22. Is there a better way?
  23. So let's back up and say, what are we doing in general?
  24. Well, we're taking a binary function f of (x,y), and we want to transform that somehow
  25. into an n_ary function--f prime, which takes x and any number of arguments.
  26. The question is, can we come up with a way to do that to automatically--
  27. change one function or modify or generate a new function from the definition
  28. of that original function.