twitter-clipboardWe’re going to improve our twitter command line program by adding support for message from clipboard: if the user just type tweet without specifying any message as parameter, the message will be read from the clipboard. So we could just type “tweet” and the message would be sent straight away to twitter.

If you just type tweet, currently the program will show an error:
rebol-optional-parameter

Looking at the source, the message parameter is mandatory:


func [message][
    if not (value? 'tweetuser) [
        tweetuser: ask "user: "
        tweetpassword: ask "password: "
    ]
    tweetaccount tweetuser tweetpassword message
]

To make it optional, we need to use the unset! pseudo-type like this:


tweet: func [message [string! unset!]][
    if not (value? 'tweetuser) [
        tweetuser: ask "user: "
        tweetpassword: ask "password: "
    ]

    if (not value? 'message) [
       message: read clipboard://
       print message
    ]

    tweetaccount tweetuser tweetpassword message
]

We’ll have to explicitely test if message has value with (not value? ‘message). If there is no message, we’ll read message from the clipboard.

Bookmark and Share