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

0 Members and 1 Guest are viewing this topic.

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 699
    • PluriBASIC
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

  • Hero Member
  • *****
  • Posts: 699
    • PluriBASIC
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

  • Hero Member
  • *****
  • Posts: 699
    • PluriBASIC
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

  • Admin Support Member
  • *****
  • Posts: 4486
    • Oxygen Basic
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 »

John

  • Hero Member
  • *****
  • Posts: 3966
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

  • Hero Member
  • *****
  • Posts: 699
    • PluriBASIC
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

  • Admin Support Member
  • *****
  • Posts: 4486
    • Oxygen Basic
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

  • Hero Member
  • *****
  • Posts: 699
    • PluriBASIC
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

  • Admin Support Member
  • *****
  • Posts: 4486
    • Oxygen Basic
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

John

  • Hero Member
  • *****
  • Posts: 3966
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

  • Hero Member
  • *****
  • Posts: 699
    • PluriBASIC
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

  • Admin Support Member
  • *****
  • Posts: 4486
    • Oxygen Basic
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

  • Hero Member
  • *****
  • Posts: 699
    • PluriBASIC
Re: unrecognized function in macro and other issue.
« Reply #12 on: August 18, 2020, 02:45:18 am »
What does using a colon do?

John

  • Hero Member
  • *****
  • Posts: 3966
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

  • Admin Support Member
  • *****
  • Posts: 4486
    • Oxygen Basic
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.