October 20, 2021, 04:18:13

Author Topic: How to use "USE cmpfunc"? And what's up with SEARCH?  (Read 2119 times)

Offline bplus

  • Full Member
  • ***
  • Posts: 228
Re: How to use "USE cmpfunc"? And what's up with SEARCH?
« Reply #15 on: April 01, 2020, 15:52:13 »
Hello experts
BYREF means by pointer or INT(address)
and there is no chance if you define
myfunc(byref a,b) that one of parameter is by value (byVal)
so both of them are pointered. :D
Then explain this:
Code: [Select]
x=1:y=2
j=dostuff(x,y)
? "after",x,y
end

func dostuff(a,byref b)
a++
b++
? "inside",a,b
dostuff=0
end func

OK LS with this I see you understand perfectly! And as Aurel says, another way to explain BYREF is the variable's address in memory is passed to procedure so variable is used inside and outside procedure and BYVAL only the value is passed to procedure and variable's value remains unchanged after the call.

We all got it! Good!

Quote
...so both of them are pointered.
Too bad about O2 ;-))

Offline lettersquash

  • Jr. Member
  • **
  • Posts: 96
    • Lettersquash Blog
Re: How to use "USE cmpfunc"? And what's up with SEARCH?
« Reply #16 on: April 01, 2020, 15:55:19 »
same result i get in oxygen basic with your code:
Well that should demonstrate to you that oxygen basic ALSO allows arguments to be passed BOTH as byref and byval.

"You reset your function to 0?"
No, I didn't reset it to zero. Zero is just a dummy value the function returns. In smallBASIC, a function has to return some kind of value, which wasn't really necessary to demonstrate that x and y were being handled differently, one as by value and the other as by reference.

Instead, I could have returned the values of a and b after they were altered in the function, like this:
Code: [Select]
x=1:y=2
j=dostuff(x,y)
? "after",x,y
? "Return value from function =",j
end

func dostuff(a,byref b)
a++
b++
? "inside",a,b
dostuff=[a,b]
end func

Here, I return them both as an array (just because it's a handy way to see them both).

You appear not to be using smallBASIC as you discuss it on the smallBASIC forum, but keep translating everything into O2B, so I'll give you the output again:
inside    2    3
outside  1    3
Return value from function =  [2,3]

This demonstrates something else. Returning a value is a way to overcome the issue of an argument passed (or rather, received) by value being lost. The line referencing j is being processed outside the function, but has [2,3], the same as the values of a and b inside the function, because they were returned. However, x, after calling the function, outside it, is unchanged, = 1. The second parameter, y, was defined in the function as byref, so is also altered when accessed outside the function after the function has been called.

Therefore:
Quote
and there is no chance if you define
myfunc(byref a,b) that one of parameter is by value (byVal)
so both of them are pointered.

is incorrect. Even in Oxygen Basic. As you demonstrated yourself.
I'll have you know, I'm coding all the right commands, just not necessarily in the right order.

Offline lettersquash

  • Jr. Member
  • **
  • Posts: 96
    • Lettersquash Blog
Re: How to use "USE cmpfunc"? And what's up with SEARCH?
« Reply #17 on: April 01, 2020, 16:01:11 »
Too bad about O2 ;-))
Too bad about Aurel. O2 does exactly the same thing.
I'll have you know, I'm coding all the right commands, just not necessarily in the right order.

Offline bplus

  • Full Member
  • ***
  • Posts: 228
Re: How to use "USE cmpfunc"? And what's up with SEARCH?
« Reply #18 on: April 01, 2020, 16:03:23 »
Too bad about O2 ;-))
Too bad about Aurel. O2 does exactly the same thing.

I was ribbing Aurel, we be friends from way back.

Offline Aurel

  • Sr. Member
  • ****
  • Posts: 351
Re: How to use "USE cmpfunc"? And what's up with SEARCH?
« Reply #19 on: April 01, 2020, 16:07:04 »
Quote
is incorrect. Even in Oxygen Basic. As you demonstrated yourself.

no is not ,you are too quick in your conclusion :

i wrote this

dostuff(a , byref b)

ehich mean that a is declared byValue and that b is declared byReference
look little bit better in a given images.

Yes i use oxygen and as you may see I get same result as you in SB which means that are processed correctly.
sorry i use 02 here because damn thing(SB) stop to work properly on my computer..why don't ask me  >:(
 BPlus ...what is bad in o2 ??? come on..you are also too quick in conclusion.
if i do that in o2
myFunc( byVal a as INT, byref b as INT) then work in a way how is defined.
(Y)

Offline Aurel

  • Sr. Member
  • ****
  • Posts: 351
Re: How to use "USE cmpfunc"? And what's up with SEARCH?
« Reply #20 on: April 01, 2020, 16:10:35 »
Quote
I was ribbing Aurel, we be friends from way back.

 :D
no...no ,,mark ..be nice
  ;D
(Y)

Offline lettersquash

  • Jr. Member
  • **
  • Posts: 96
    • Lettersquash Blog
Re: How to use "USE cmpfunc"? And what's up with SEARCH?
« Reply #21 on: April 01, 2020, 16:51:50 »
Quote
is incorrect. Even in Oxygen Basic. As you demonstrated yourself.

no is not ,you are too quick in your conclusion :

i wrote this

dostuff(a , byref b)

ehich mean that a is declared byValue and that b is declared byReference
look little bit better in a given images.
Oh for god's sake have a bit of humility and accept when you made a mistake! You did the same in O2 as my version in sB, and your version showed:

Quote
and there is no chance if you define
myfunc(byref a,b) that one of parameter is by value (byVal)
so both just one of them are is pointered.

Quote
Yes i use oxygen...
Well we all use oxygen. Some of us don't waste it though.
I'll have you know, I'm coding all the right commands, just not necessarily in the right order.

Offline Aurel

  • Sr. Member
  • ****
  • Posts: 351
Re: How to use "USE cmpfunc"? And what's up with SEARCH?
« Reply #22 on: April 01, 2020, 19:09:12 »
LS
I really don't know about what kind of mistake you talking about man.
it is logical to me if

myFunc(byref a,b)

that both parameters are defined by reference
Is that right?

Also both of examples mine in Oxygen basic and your in small basic show same result.
In which one param is byValue and another byReference.
so there is no any kind of mistake.
jeez.... ???
(Y)

Offline lettersquash

  • Jr. Member
  • **
  • Posts: 96
    • Lettersquash Blog
Re: How to use "USE cmpfunc"? And what's up with SEARCH?
« Reply #23 on: April 01, 2020, 19:29:40 »
LS
I really don't know about what kind of mistake you talking about man.
it is logical to me if

myFunc(byref a,b)

that both parameters are defined by reference
Is that right?
No, that's wrong. It's not logical. a is defined as by reference, b is not (because the default condition is by value).

Quote
Also both of examples mine in Oxygen basic and your in small basic show same result.
In which one param is byValue and another byReference.
That's right. They both show that.

Quote
so there is no any kind of mistake.
jeez.... ???
Yes, there is. The one I quoted. Where you said:
Quote
and there is no chance if you define
myfunc(byref a,b) that one of parameter is by value (byVal)
so both of them are pointered.


Unless your English is so bad that you mean the opposite of how that reads. It looks like you're saying:
If you define myfunc(byref a,b), then there is no chance that only one of the parameters is by value. Both of them are "pointered" (by reference).

If you meant the opposite, then I'm sorry I misunderstood you, but I'm pretty convinced most people will read it that way. You now have clarified (as far as I can tell) that the opposite is actually the case. Personally, I think you just jumped in, telling us "experts" how it is, and got it wrong, but you're too insecure to admit you could possibly make a mistake.
I'll have you know, I'm coding all the right commands, just not necessarily in the right order.

Offline Aurel

  • Sr. Member
  • ****
  • Posts: 351
Re: How to use "USE cmpfunc"? And what's up with SEARCH?
« Reply #24 on: April 01, 2020, 19:45:11 »
sorry ..
yes i made mistake ,my bad i think that is same thing in o2 and in SB
in o2 means  if byREF is first  then both params are byREF and i see now that in sb is different
and each param need to be signed.
OK
I also made mistake when i say about o2.
in o2 default is byref that is why both examples show same result.
sorry once again about all this confusion
 :D
so i will shut up byVAL   :D :D :D
« Last Edit: April 01, 2020, 19:54:06 by Aurel »
(Y)

Offline lettersquash

  • Jr. Member
  • **
  • Posts: 96
    • Lettersquash Blog
Re: How to use "USE cmpfunc"? And what's up with SEARCH?
« Reply #25 on: April 01, 2020, 20:04:45 »
sorry ..
yes i made mistake ,my bad i think that is same thing in o2 and in SB
in o2 means  if byREF is first  then both params are byREF and i see now that in sb is different
and each param need to be signed.
OK
I also made mistake when i say about o2.
in o2 default is byref that is why both examples show same result.
sorry once again about all this confusion
 :D
OK, well that only took most of a day. Can I politely suggest you discuss oxygen basic at the relevant forum. It's confusing here.
I'll have you know, I'm coding all the right commands, just not necessarily in the right order.

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal