(vote) varargs / params feature

Home Forums Monkey 2 Development (vote) varargs / params feature

This topic contains 8 replies, has 3 voices, and was last updated by  nerobot 2 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #10884

    nerobot
    Participant

    Is it useful for you to have params feature in Monkey2?

    Shortly: it’s an easy way to pass various number of parameters (with the same type).

    Internally our params is an usaul array.

    More info: https://msdn.microsoft.com/en-us/en-en/library/w5zay9db(v=vs.110).aspx

    #10933

    cocon
    Participant

    From what I guess (based on similar threads) Mark wants to avoid syntactic sugar additions (unless they are mostly essential) in order to keep the parser thin and lightweight, perhaps I might be mistaken.

    If the feature won’t make to the parser API hacks can be used for sure. This concept is based on factory patterns – to encapsulate the logic of creating stuff.

    In the example below, the motivation is to pack variables into an array and return the array. The function overloading works like a dream here because it makes  things very simple – a similar approach was used in the Tuples example I made earlier.

    In this case if you dislike the API naming, perhaps other more meaningful names can be found, perhaps even extending the std Array class to form a smooth integration.

    #10935

    nerobot
    Participant

    Idea is to hide Params.Create under the hood to simplify code.

    From what I guess (based on similar threads) Mark wants to avoid syntactic sugar additions (unless they are mostly essential)

    I created thit topic to ask if anybody like it and have usecases, looking at this Mark can decide to implement that or not. 🙂

    #10957

    cocon
    Participant

    I would like it also as well. 🙂

    #10980

    scurty
    Participant

    Seems to me like a basic form of an initializer list as seen in C++.
    Hmm, I feel like we should fuse this concept with the tuples so the type could vary from param to param.
    Definitely useful in game programming for sure when initializing component based entities.

    #10981

    nerobot
    Participant

    @scurty

    Hmm, I feel like we should fuse this concept with the tuples so the type could vary from param to param.

    Can you explain that concept?

    For components you can declare function with base type Component and pass any derived types.

    #10982

    scurty
    Participant

    Well as it’s stated you can only pass a shared data type with “Params” but if you could pass a string and an int within the same line(like passing a tuple) you could state attributes for a character controller-like component that takes arguments like initializing the new RPG character or something similar.

    Name:String
    Description
    Age:Int
    JumpHeight:Double
    AttackValue:Double

    You could do:

    #10983

    nerobot
    Participant

    You said about different things.

    We discuss here special keyword Params (or Varargs), which is used as an addition to array type.

    It has the only purpose – allow to pass varying params count, but all of them with the same type.

    Would work with typles as well because they are an usual type (if will be added 🙂 ):

    #11066

    nerobot
    Participant

    Usecase: c#-like string.Format() where {0},{1},… will be replaced with args[i] in order you pass params.

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.