Best way to make functions?



  • What's the best way to make a function?
    I just want a block of code that I can use repeatedly with an input and an output :O

    Edit: I think it's possible with Dictionaries and Broadcast/Recieve message. I'm using the dictionary to store arguments and outputs. But I have some questions.

    1. when a dictionary is passed through broadcast to recieve, is the pointer passed, or the value? Is it possible to use a pointer to the dictionary?

    2. if I call a behavior bundle, will the next block execute immediately or once that behavior bundle has completed?



  • @domination I was wondering this too.



  • @domination A function as in like a calculation? Behaviour blocks execute from top to bottom THEN left to right. Say if you have a receive message, with a behaviour bundle under it, stuff under the behaviour bundle then some other behaviour to the right of the behaviour bundle, everything underneath the behaviour bundle will happen first, then whatever was to the right of the behaviour bundle. If that makes sense 🙂



  • @aidan-oxley I meant a function as in regular code.



  • @domination

    Can you give me an idea of your favourite other programming languages and environments so I can explain it in those terms and help you see how to do something like functions in hyperPad?

    @Aidan-Oxley has come up through learning coding via hyperPad, so far as I know.

    And hyperPad doesn't have functions as seen in regular paradigms of the majority of common programming languages.

    You can do a faking of the sort of separation you get from functions by using messaging, but it's not really the same thing, and seems to have diabolical impact on build time when used between layers and many objects.

    It will take some time to explain, though, hence the request for some background info on what you know to help communicate this as fast as possible.



  • @deeeds I'm currently using Go. Know JavaScript as well and a little bit of C++.



  • @domination

    func myFunction(parameterA, parameterB int) returnValue int  {}
    

    is possible to replicate, but you have to jump through hoops.

    Firstly, there's no way to send more than one thing in a message, which is the best way to make this possible. So instead of sending the values for parameters in the function call, it's best to set values in a storage container to be used by the function.

    How to think of this:

    Message Broadcast with Name is the function call. The message title (Key) can be thought of as the name of the function. The Broadcast value can be used as a tool for overloading, to pass into the function or to determine what the function does.

    A Box Container, Dictionary, Array or set of Value Behaviours can be used to store the parameter values.

    The receiver of the message holds the function, and looks to the container(s) for parameter values to operate on. In the same way, the "function" can send/store values to known containers for the return, and call any other behaviours to either execute them, turn them on and execute them, turn them on/off to change their state and/or send a message to another "function" receiver.



  • @deeeds this is similar to what I had going before.
    I used the message key as the name and sent a dictionary through the message value. A callback key could also be sent in the argument dictionary so when the function finishes, it can broadcast a message back to the caller.

    e.g:

    But I still have a few concerns. If I call the function again before it finishes, it will be interrupted. Also, it's a lot of junk to work with to do something that should be simple and would be beneficial.
    This method probably doesn't have optimal performance either.



  • @domination said in Best way to make functions?:

    This method probably doesn't have optimal performance either.

    good pun!!!!



  • @domination said in Best way to make functions?:

    Also, it's a lot of junk to work with to do something that should be simple and would be beneficial.

    agreed!!!!!!!!!!!!

    https://forum.hyperpad.com/topic/771/known-issues-limitations-of-hyperpad



  • good pun!!!!

    @Deeeds not intended


Log in to reply
 

Looks like your connection to hyperPad Forum was lost, please wait while we try to reconnect.