[mgmt] Function Values Design

James purpleidea at gmail.com
Thu May 23 20:55:56 UTC 2019


I'm currently working on implementing function _values_ in mgmt. You
might like to think of these as lambdas. I came across an interesting
edge case, and I figured I would post it here for discussion. I have
not yet decided which approach I will take, but I might do so shortly.
Comments welcome now, or you'll forever have to live with the decision
;)

Look at the following mgmt code:

import "fmt"

# this is a lambda
$add = func($x) {
	# the plus operator can be used for concat
	# of strings,
or addition of numbers
	$x + $x
}

$num = 2
$out1 = $add($num) # 4

test fmt.printf("%d + %d is %d", $num, $num, $out1) {} # simple math

$val = "hello"
$out2 = $add($val) # hellohello

test fmt.printf("%s + %s is %s", $val, $val, $out2) {} # simple concat


Question! Should the above code compile or not?

Before I explain _my_ reasoning for yes or no, I'd love to hear your
comments. I'm avoiding elaborating on this, because I don't want to
influence your decision.

Happy Hacking,
James
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://listman.redhat.com/archives/mgmtconfig-list/attachments/20190523/74b393e4/attachment.sig>


More information about the mgmtconfig-list mailing list