Skip to content

Conversation

herwinw
Copy link
Contributor

@herwinw herwinw commented Mar 10, 2021

A branch I had around. It's pretty much a direct copy from the C function, with a few remarks:

  • I'm not sure what the return type of the call for a sparse array is. It calls jteps, which confuses me a lot. I'm not even sure why it does this.
  • I thought about rewriting AN to something more descriptive, similar to the is_sparse function. However, this macro is used for assignment as well (see make_array), so I just left the C macro here. I think the consistency here is more important.

herwinw added 4 commits March 10, 2021 21:28
For now it's a direct copy of the original C code, with a nodiscard
added to be on the safe side.
* Replace `A` with `array`
* Use trailing return types
@juntuu
Copy link
Collaborator

juntuu commented Mar 11, 2021

About the first point: jteps(jt, needle, haystack) implements x e. y which is "member in".
So in english, for sparse array jtisempty checks if zero is in the shape of the array (as the comment also says in j).

Generally the functions often have commented the corresponding j phrase, if not t.c is good place to check for primitives. Here for example jtrazein is the monadic case, and jteps is dyadic case of e..

/* e. */ PRIMACV(CEPS, VERB, jtrazein, jteps, RMAX, RMAX, RMAX, VASGSAFE | VIRS2, VF2NONE),
(and j nuvoc to see what the primitive does)

@codereport codereport mentioned this pull request Mar 15, 2021
4 tasks
@herwinw
Copy link
Contributor Author

herwinw commented Mar 16, 2021

That makes more sense than the epsilon how I read it

Copy link
Owner

@codereport codereport left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 🙏 just a file rename / function rename and then we will 🚢 it

verbs/vsb.c
verbs/vx.c
verbs/vz.c
verbs/monadic/isempty.cpp
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
verbs/monadic/isempty.cpp
verbs/monadic/is_empty.cpp

* @return boolean jtrue or jfalse
*/
[[nodiscard]] auto
jtisempty(J jt, array w) -> array {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
jtisempty(J jt, array w) -> array {
is_empty(J jt, array w) -> array {

/**
* @brief `0 e. $` IsEmpty
* @param jt JST (J Syntax Tree)
* @param w Input aray
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a typo

Suggested change
* @param w Input aray
* @param w Input array

@codereport codereport added the c to c++ Porting C code to C++ label Mar 17, 2021
@herwinw herwinw closed this by deleting the head repository Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c to c++ Porting C code to C++

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants