Author Topic: unrecognized function in macro and other issue.  (Read 2143 times)

0 Members and 1 Guest are viewing this topic.

Brian Alvarez

  • Guest
unrecognized function in macro and other issue.
« on: August 16, 2020, 10:37:11 AM »
 Hello Charles, im trying to overcome the fact that i cannot place comparisons directly as the parameter of a function. For example, this is not allowed by Oxygen:

Code: [Select]
function isequal(int *c) as long
    return c
end function

print isequal("a" = "b")

Using this is allowed though:

Code: [Select]
print isequal(("a" = "b"))
But then it creates the same issue (when using functions) that I explain next. The problem is in the following code:

Code: [Select]
function something(string s) as string
    return "I exist!"
end function

MACRO testbyte int(r, v  b)
    int b = (v)
    'code to determine the value of r goes here.
    r = b
END MACRO

print testbyte(something("a") = "A")

Complains like this:

Code: [Select]
ERROR: Linker found unidentified names:
1074 something "main source

What i understand is that it does not recognize something as a valid function name... but it IS valid.

If i change the macro like this:

Code: [Select]
MACRO testbyte int(r, v)
    r = v
END MACRO

I expect the macro to place a false or true value in r, depending on the result of a comparison, but instead i get this compile-time error:

Code: [Select]
ERROR: ERROR: parameters mismatch for procedure something
params given : #string#string@00

OPTIONS:
something(string) returns string


WORD: "A"
LINE: 1072
FILE: "main source

It seems to "think" i passed two strings as parameters of something (kind of like a class property method), when in fact i just tried to compare them.

Changing the macro like this:

Code: [Select]
MACRO testbyte int(r, v)
    r = (v)
END MACRO

Goes back to:

Code: [Select]
ERROR: Linker found unidentified names:
1072 something "main source




« Last Edit: August 16, 2020, 11:08:18 AM by Brian Alvarez »

Brian Alvarez

  • Guest
Re: unrecognized function in macro and other issue.
« Reply #1 on: August 16, 2020, 10:53:27 AM »

Same thing happens with native features:

Code: [Select]
MACRO testbyte int(r, v)
    r = v
END MACRO

print testbyte((lcase("a") = "a"))

Brian Alvarez

  • Guest
Re: unrecognized function in macro and other issue.
« Reply #2 on: August 16, 2020, 11:06:36 AM »

This is the issue i was talking about in the first post of this thread:

Code: [Select]
function testbyte (int v) as long
    return v
END function

print testbyte((lcase("a") = "a"))


Charles Pegge

  • Guest
Re: unrecognized function in macro and other issue.
« Reply #3 on: August 16, 2020, 12:10:04 PM »
Horrible code!. Imagine someone trying to comprehend this code in a large script.

You will always need to enclose the logical expression parameter inside brackets.

This works with 0.2.9

Code: [Select]
function testbyte (int v) as int
return v
end function

print testbyte( ( lcase("A") = "a") )

« Last Edit: August 17, 2020, 05:34:53 AM by Charles Pegge »

JRS

  • Guest
Re: unrecognized function in macro and other issue.
« Reply #4 on: August 16, 2020, 03:48:53 PM »
I gave the testbyte example a try in ScriptBasic and it returned a TRUE (-1) result.

Code: Script BASIC
  1. FUNCTION testbyte(c)
  2.   testbyte = c
  3. END FUNCTION
  4.  
  5. PRINT testbyte(LCASE("A") = "a"), "\n"
  6.  


C:\ScriptBASIC\examples>sbc testbyte.sb
-1

C:\ScriptBASIC\examples>



This simplified version returns the same result.

Code: Script BASIC
  1. PRINT LCASE("A") = "a", "\n"
  2.  

« Last Edit: August 16, 2020, 03:57:10 PM by John »

Brian Alvarez

  • Guest
Re: unrecognized function in macro and other issue.
« Reply #5 on: August 16, 2020, 05:35:21 PM »
Horrible code!. Imagine someone trying to comprehend this code in a large script.

 I agree is not very nice, unfortunately it is required for the new feature i am working on, otherwise  I would
need to split all the statements myself and would end up being worse for the comprehension in large scripts.

 The new feature is custom operators. Its almost done.

Charles Pegge

  • Guest
Re: unrecognized function in macro and other issue.
« Reply #6 on: August 17, 2020, 05:34:12 AM »
The brackets are mainly required to distinguish logical expressions from o2's html-like default param setting. For example:

DrawCube( size=2.5, color=red)

Brian Alvarez

  • Guest
Re: unrecognized function in macro and other issue.
« Reply #7 on: August 17, 2020, 01:05:53 PM »
Charles, does this mean the order of the parameters can be changed?
« Last Edit: August 17, 2020, 02:06:46 PM by Brian Alvarez »

Charles Pegge

  • Guest
Re: unrecognized function in macro and other issue.
« Reply #8 on: August 17, 2020, 05:50:27 PM »
Yes.

Code: [Select]
function drawcube(int color=0,int size=1)
print color " " size
end function

drawcube( size=2, color=0xff) '255 2

JRS

  • Guest
Re: unrecognized function in macro and other issue.
« Reply #9 on: August 17, 2020, 07:54:02 PM »
I'm confused. Are you trying to set an argument variable with a constant before passing it? Why not just pass the constant?

I've always thought FUNCTION argument variables were 'placeholders' and not a reference to other variables with the same name. Is this unique to O2?
« Last Edit: August 17, 2020, 08:30:26 PM by John »

Brian Alvarez

  • Guest
Re: unrecognized function in macro and other issue.
« Reply #10 on: August 17, 2020, 09:08:07 PM »
John, this is the way some modern languages work. Have you tried swift? Check this out: https://docs.swift.org/swift-book/LanguageGuide/Functions.html

Charles, how does one know what parameters were passed to the module? Also, it would be nice if this behavior was like this:

Code: [Select]
drawcube(size:2, color:0xff) '255 2
 That way you could still use functions like:

Code: [Select]
print iif(answer=correct, "YES", "NO")
 Also it is a little more common to see it like this. I didnt know oxygen had this super power!! Kudos!

 Just my 2 cents.
« Last Edit: August 17, 2020, 10:16:18 PM by Brian Alvarez »

Charles Pegge

  • Guest
Re: unrecognized function in macro and other issue.
« Reply #11 on: August 18, 2020, 12:47:00 AM »
Unfortuntely, we have exhausted the uses of the colon in BASIC.

Code: [Select]
drawcube(size:2, color:0xff) '255 2

Brian Alvarez

  • Guest
Re: unrecognized function in macro and other issue.
« Reply #12 on: August 18, 2020, 02:45:18 AM »
What does using a colon do?

JRS

  • Guest
Re: unrecognized function in macro and other issue.
« Reply #13 on: August 18, 2020, 09:17:41 AM »
Quote
John, this is the way some modern languages work. Have you tried swift?

I just pass an associative array if I need named arguments in a function.

Thanks for the clarification!

Charles Pegge

  • Guest
Re: unrecognized function in macro and other issue.
« Reply #14 on: August 18, 2020, 07:32:51 PM »
The colon is primarily used as a statement separator, but is also used for labels, and namespaces, so I would not want to use it as an assignment operator as well.