Author Topic: Slightly esoteric WEIDU requests  (Read 183 times)

Offline DavidW

  • Planewalker
  • *****
  • Posts: 237
Slightly esoteric WEIDU requests
« on: September 11, 2018, 12:12:50 AM »
I suspect these are only useful to me; I'll list them in increasing order of presumed implausibility.

1) The ability to detect whether a given string actually names a function. At the moment I do it with TRY: run the function, if it doesn't run then catch the exception and return that it doesn't exist. But it's scarcely elegant.

Illustrative syntax:     PATCH_IF IS_A_FUNCTION "%function%" THEN ...

2) Morphic functions that work either as ACTION or PATCH functions (say, with ACTION syntax for definiteness). So I define it with DEFINE_MORPHIC_FUNCTION, just as if it were an action function, then if I call the function in a patch it acts as if there was an INNER_ACTION present.

3) The ability for a function to return an array indexed by something other than integers. As in:
Code: [Select]
DEFINE_ACTION_FUNCTION my_function
RET_HASH blook
BEGIN

ACTION_DEFINE_ASSOCIATIVE_ARRAY blook BEGIN
this=>that
END
END

4) (This is a fairly wild ask, but...) access to a WEIDU version of OCAML lists. Something like

Code: [Select]

MAKE_LIST my_list first_entry second_entry third_entry

OUTER_SPRINT head (LIST_HEAD my_list)
LIST_TAIL my_tail my_list

SCS uses that format very extensively, but it has to fake it up: my "lists" are just space-separated strings, and I have functions to extract things from them, but I think I pay a reasonably high install-time price. I wouldn't even ask except that I assume the functionality is in OCAML anyway and it *might* be possible to expose it to WEIDU.

Offline Wisp

  • Moderator
  • Planewalker
  • *****
  • Posts: 986
Re: Slightly esoteric WEIDU requests
« Reply #1 on: September 11, 2018, 12:28:35 PM »
I'll get back to you on the other stuff, but for #3, RET_ARRAY has no such limitation.

Offline DavidW

  • Planewalker
  • *****
  • Posts: 237
Re: Slightly esoteric WEIDU requests
« Reply #2 on: September 11, 2018, 02:51:00 PM »
That's fantastic. (Off to rewrite SCS's function library.)

Offline DavidW

  • Planewalker
  • *****
  • Posts: 237
Re: Slightly esoteric WEIDU requests
« Reply #3 on: September 11, 2018, 02:58:05 PM »
Actually, one follow-up: can I pass arrays as arguments to functions?

Offline Argent77

  • Planewalker
  • *****
  • Posts: 165
Re: Slightly esoteric WEIDU requests
« Reply #4 on: September 11, 2018, 04:03:31 PM »
Actually, one follow-up: can I pass arrays as arguments to functions?
I don't think that's possible. And a feature like this would probably introduce a noticeable performance hit.

However, you can pass the array name for use in a function. Example:
Code: [Select]
DEFINE_ACTION_FUNCTION MY_FUNC
STR_VAR array_name = ~~
BEGIN
  ACTION_PHP_EACH EVAL ~%array_name%~ AS key => value BEGIN
    PRINT ~Func: %key% -> %value%~
  END
END

ACTION_DEFINE_ASSOCIATIVE_ARRAY my_array BEGIN
  ~key1~ => ~value1~
  ~key2~ => ~value2~
  ~key3~ => ~value3~
END

ACTION_PHP_EACH my_array AS key => value BEGIN
  PRINT ~Global: %key% -> %value%~
END

LAF MY_FUNC
STR_VAR array_name = ~my_array~
END

Offline DavidW

  • Planewalker
  • *****
  • Posts: 237
Re: Slightly esoteric WEIDU requests
« Reply #5 on: September 11, 2018, 05:12:43 PM »
Yes, of course; that works fine.

 

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
What color is grass?:
What is the seventh word in this sentence?:
What is five minus two (use the full word)?: