Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Design for Python-like functions in Oil #1112

Closed
andychu opened this issue Apr 25, 2022 · 5 comments
Closed

Design for Python-like functions in Oil #1112

andychu opened this issue Apr 25, 2022 · 5 comments

Comments

@andychu
Copy link
Contributor Author

andychu commented Apr 25, 2022

It's related to error handling, because procs have exit codes, and a expression like 1 / 0 logically raises an exception

@andychu
Copy link
Contributor Author

andychu commented Apr 25, 2022

Key question: Are functions vectorized ?

I think they can use QTT for args and return values. So you get the args on stdin. And then you return on stdout.

And a non-zero exit code is turned into a fatal "exception"? It aborts the recursive expression evaluation, which again turns into an exit code at the statement/command level.

Something like this, but we also need headers

proc myfunc {
  while read --qtt :left :right {
    write -- $[left + right]
  }
}

Or maybe

proc myfunc {
  read-qtt-header  # suppose the header is "left right".  Maybe it fills _schema or _header
  while read-qtt-row {
    write $[_row->left + _row->right]
  }
}

define :myfunc {  # this is a builtin that assigns to a variable?  functions are variables that wrap procs?
  format = 'qtt'  # can also be JSON for non-primitive data
}

Do we have multiple types of functions -- vectorized and non-vectorized?

The vectorized ones are more typed with QTT ?

@andychu
Copy link
Contributor Author

andychu commented Aug 13, 2022

I think we should consider putting user-defined functions and builtin functions in the "proc" namespace, sort of like a Lisp 2

And then have var len = get_func('len') and var foo = get_proc('foo') to unify them. I guess you might need that for sorting comparators or something?

$ bin/osh -c 'echo $len'
  echo $len
  ^~~~
[ -c flag ]:1: fatal: Expected evaluation to Bool, Int, or Str.  Got <type 'builtin_function_or_method'>

@andychu
Copy link
Contributor Author

andychu commented Aug 31, 2022

Feedback here on potential (syntactic and semantic) confusion between procs and funcs

https://oilshell.zulipchat.com/#narrow/stream/264891-oil-help/topic/_.20versus.20.28.29.20for.20append

It is a hard design problem

@andychu
Copy link
Contributor Author

andychu commented Jan 17, 2024

Done - future work described here https://www.oilshell.org/blog/2024/01/release-0.19.0.html

@andychu andychu closed this as completed Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant