#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Location
    Isle of dogs
    Posts
    68
    Rep Power
    10

    Talking Smalltalk style named parameters


    Named parameters
    I what to know how to create named parameters, like how they do in smalltalk. So ordering isn't required. Example

    person =method(age=”65”,name=”Gordon Brown”,sex=”male”) <-is the same as
    person =method(sex=”male”,name=”Gordon Brown”,age=”65”) <- this
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    You can do exactly that with any Python function/method call - just call the function with its parameter list like you did above.
    programming language development: www.netytan.com Hula

  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    This example shows several ways of passing arguments to a function/methods; ordered and unordered:

    Code:
    >>> def foo(param1, param2, param3):
    ...     print param1, param2, param3
    ... 
    >>> foo('one', 'two', 'three')
    one two three
    >>> foo(param1 = 'one', param3 = 'three', param2 = 'two')
    one two three
    >>> params = ('one', 'two', 'three')          
    >>> params
    ('one', 'two', 'three')
    >>> foo(*params)
    one two three
    >>> params = {'param1': 'one', 'param3': 'three', 'param2': 'two'}
    >>> params
    {'param3': 'three', 'param2': 'two', 'param1': 'one'}
    >>> foo(**params)
    one two three
    >>>
    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo