brazilofmux / tinymux

TinyMUX
www.tinymux.org
48 stars 21 forks source link

#LAMBDA #361

Open brazilofmux opened 9 years ago

brazilofmux commented 9 years ago

Original issue 358 created by brazilofmux on 2007-08-07T00:28:46.000Z:

Please add #LAMBDA support.

What version of the server are you using? On what operating system? What is the configuration or initial setup is required? blah What steps will reproduce the problem?

  1. blah
  2. blah
  3. blah

What is the expected output? blah

What output do you see instead? blah

Please provide any additional information below.

Please add #LAMBDA support.

brazilofmux commented 9 years ago

Comment #1 originally posted by brazilofmux on 2007-08-11T01:16:50.000Z:

Mark as an enhancment.

brazilofmux commented 9 years ago

Comment #2 originally posted by brazilofmux on 2007-08-19T15:29:05.000Z:

Syntax is typically somefunction(#LAMBDA/[expression], usual arguments) in the case where somefunction has a normal syntax, somefunction(obj/attribute, usual arguments).

The #LAMBDA/[expression] is executed in place rather than requiring a call-out to an object/attribute for the helper function.

For example, you could use sortby(#LAMBDA/[comp(name(%0),name(%1))], lwho()).

brazilofmux commented 9 years ago

Comment #3 originally posted by brazilofmux on 2007-09-21T00:04:59.000Z:

While this may improve the expressive power of MUSHcode, it's hard to argue that it is a higher priority than other issues.

brazilofmux commented 9 years ago

Comment #4 originally posted by brazilofmux on 2009-09-29T05:01:23.000Z:

From PennMUSH help for compatibility:

LAMBDA

In many cases where a function expects a object/attribute pair that refers to an attribute to evaluate, you can use the form

lambda/

instead, and the code will be treated as an attribute's body. The code will normally be parsed twice, so special characters should be escaped where needed.

These anonymous attributes should be used for short and simple pieces of code. Anything long or complicated should go in an actual attribute, for readability and maintainability.

See 'HELP ANONYMOUS2' for examples.

ANONYMOUS2 A typical usage of anonymous attributes would be to convert a list of dbrefs to names, as so:

say map(#lambda/name(\%0), # 3 # 12 # 23) You say, "Joe Robert Sally"

Because the code is parsed twice, you can actually build parts of it in place, which is very convenient. Consider this implementation of a lattrval function, which is like lattr() but it only returns non-empty attributes:

&lattrval me= filter(#lambda/hasattrval([secure(before(%0, /))], \%0), lattr(%0))

The first time '#lambda/hasattrval([secure(before(%0, /))], \%0)' is parsed in a call like 'u(lattrval, # 1234)', it is turned into '#lambda/hasattrval(# 1234, %0)', thus avoiding the need for a setq() or the like to store the top-level %0 for use in a real attribute called by filter(). However, this can lead to problems with evaluating un-trusted code. Use secure() or escape() where neccessary.

See 'HELP ANONYMOUS3' for another example.

ANONYMOUS3

You can also use lit() to avoid having the code evaluated twice, if needed. For example, this code, which returns all unlinked exits in a room:

&lunlinked me=filter(lit(#lambda/strmatch(loc(%0), #-1)), lexits(%0))

This approach is useful both for security in making it harder to evaluate a string that shouldn't be, and for making the code look nicer by not having to escape percent signs, brackets, and other special characters. However, it also makes it harder to build the code string on the fly. Use what's most appropriate.

See 'HELP ANONYMOUS4' for a list of functions that support anonymous attributes.

ANONYMOUS4 The following functions support anonymous attributes:

filter() filterbool() fold() foreach() map() mapsql() mix() munge() sortby() sortkey() step()

brazilofmux commented 9 years ago

Comment #5 originally posted by brazilofmux on 2009-09-29T05:01:36.000Z:

<empty>