Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Optional arguments

Name: Anonymous 2011-07-27 6:13


def find(str, ch, start=0):
  index = start
  while index < len(str):
    if str[index] == ch:
      return index
    index = index + 1
  return -1


Add a fourth parameter, end, that specifies where to stop looking. The default value of end should be len(str).

Name: Anonymous 2011-07-27 6:19

def find(str, ch, start=0, end=None):
  index = start
  if end is None:
    end = len(str)
  while index < len(str):
    if index > end:
      break
    if str[index] == ch:
      return index
    index = index + 1
  return -1

Name: Anonymous 2011-07-27 6:24

What about keywords? Like (draw-circle O R :filled T :color +RED+) Can Python do keywords?

Name: Anonymous 2011-07-27 6:29

>>3
It can, and I'm a Python hater. In fact, I'm going to say that keyword parameters are indistinguishable from optional parameters.

Name: Anonymous 2011-07-27 6:38

>>2
Symta:

find Str Ch Start=0 End=0
 -> cut Start End Str | ([I++_ !Ch @_]->I) |> Start+It :: ~1


Python:

def find(str, ch, start=0, end=None):
  index = start
  if end is None:
    end = len(str)
  while index < len(str):
    if index > end:
      break
    if str[index] == ch:
      return index
    index = index + 1
  return -1

Name: Anonymous 2011-07-27 6:41

>>5
Both are terrible and harmful, their creator is a huge elitist visionary faggot that understands nothing about language design? I see no difference.

Name: Anonymous 2011-07-27 7:14

Unscientific and ultimately DESTRUCTIVE!

[1]> (position #\o "Hello, world!"
4
[2]> (position #\o "Hello, world!" :start 5 :end 9)
8

Name: sage 2011-07-27 7:15

forgot my closing parenthesis :(

Name: Anonymous 2011-07-27 7:24

>>5
All I can see is: 8==B~ ~C=8

Name: Anonymous 2011-07-27 8:17

>>6
implying one can find here non-terrible, non-harmful code

Name: Anonymous 2011-07-27 22:05

>>5
Has there been a new Symta Lisp release yet?

Don't change these.
Name: Email:
Entire Thread Thread List