-
Sep 26th, 2022, 04:27 AM
#1
Partial function in VB6?
I wonder if partial function is possible with VB6 or not. The following code is the C# version, I've already created a working Python and C++ version but I would want to do it in VB6 also if it is possible.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
class PartialFunctionApplication
{
static Func<T1, TResult> PartiallyApply<T1, T2, TResult>(Func<T1, T2, TResult> function, T2 argument2)
{
return argument1 => function(argument1, argument2);
}
static void Main()
{
var fs = (Func<IEnumerable<int>, Func<int, int>, IEnumerable<int>>)Enumerable.Select;
var f1 = (Func<int, int>)(n => n * 2);
var f2 = (Func<int, int>)(n => n * n);
var fsf1 = PartiallyApply(fs, f1);
var fsf2 = PartiallyApply(fs, f2);
var s = new[] { 0, 1, 2, 3 };
Console.WriteLine(string.Join(", ", fsf1(s)));
Console.WriteLine(string.Join(", ", fsf2(s)));
s = new[] { 2, 4, 6, 8 };
Console.WriteLine(string.Join(", ", fsf1(s)));
Console.WriteLine(string.Join(", ", fsf2(s)));
}
}
-
Sep 26th, 2022, 04:52 AM
#2
Re: Partial function in VB6?
You had me very confused at first as I was thinking "partial methods" and thought that this had nothing to do with that. It does indeed have nothing to do with that, because you're talking about something else entirely. Order restored.
-
Sep 26th, 2022, 06:58 AM
#3
Re: Partial function in VB6?
That looks like generics to me... not partial... which is a completely different thing. Also I don't think you can have partial functions/methods - in any language - partial classes, sure. Methods, no. It wouldn't make sense. Generics though... sure that makes sense. Whether VB6 can do it or not... shrug. I honestly don't know. Never thought about it.
-tg
-
Sep 26th, 2022, 08:12 AM
#4
Re: Partial function in VB6?
Originally Posted by techgnome
That looks like generics to me... not partial... which is a completely different thing. Also I don't think you can have partial functions/methods - in any language - partial classes, sure. Methods, no. It wouldn't make sense. Generics though... sure that makes sense. Whether VB6 can do it or not... shrug. I honestly don't know. Never thought about it.
-tg
Here's an article about partial functions in python:
https://www.udacity.com/blog/2020/12...in-python.html
-
Sep 26th, 2022, 08:49 AM
#5
Re: Partial function in VB6?
Originally Posted by techgnome
That looks like generics to me... not partial... which is a completely different thing. Also I don't think you can have partial functions/methods - in any language - partial classes, sure. Methods, no. It wouldn't make sense. Generics though... sure that makes sense. Whether VB6 can do it or not... shrug. I honestly don't know. Never thought about it.
-tg
I think that you made the same misinterpretation that I did initially. This is nothing to do with partial classes and partial methods. This is a functional programming concept.
-
Sep 26th, 2022, 09:28 AM
#6
Hyperactive Member
Re: Partial function in VB6?
Even getting VB to call a function pointer at all takes some hacks, let alone using it generically.
The closest you could get would be doing everything totally late-bound, with CallByName.
-
Sep 28th, 2022, 06:15 AM
#7
Re: Partial function in VB6?
Originally Posted by dee-u
Here's the python-example expressed in VB6/VBA-code:
Function-def of the "large function" (Pythonstyle)
Code:
Function multiply(x, y)
multiply = x * y: End Function
Function-def of a "manually derived" partial-function (using named parameters, to rule-out mistakes):
Code:
Function times_12(y)
times_12 = multiply(x:=12, y:=y): End Function
TestCode:
Code:
Sub Main()
Debug.Print multiply(6, 7) '42
Debug.Print times_12(2) '24
End Sub
HTH
Olaf
-
Sep 28th, 2022, 07:15 AM
#8
Re: Partial function in VB6?
I must be missing something fundamental, because I don't see a new paradigm in this..
-
Sep 28th, 2022, 07:43 AM
#9
Re: Partial function in VB6?
Originally Posted by Arnoutdv
I must be missing something fundamental, because I don't see a new paradigm in this..
I'm no expert so I might be missing something but I suspect that that's because it's an attempt to implement a functional programming concept in other than a functional programming language, so it requires stuff we already use and recognise to do something we don't usually try to do. I suspect that what's going on would be clearer in F#.
-
Sep 28th, 2022, 10:42 AM
#10
Re: Partial function in VB6?
Originally Posted by Arnoutdv
I must be missing something fundamental, because I don't see a new paradigm in this..
That's probably, because there is none...
Olaf
-
Sep 28th, 2022, 10:48 AM
#11
Re: Partial function in VB6?
To understand currying you have to have first-class functions in the language i.e. being able to assign functions to variables like Dim a As Variant : a = MyFunction is not available in VB6.
-
Sep 28th, 2022, 11:10 AM
#12
Re: Partial function in VB6?
I'm picturing tons of bad code out there that falls apart under maintenance. It uses such "features" by stumble-bum accident and cargo-culting and it works... until later when the house of cards comes down.
It feels like the sort of trash only a script kiddie could love. If it has any value then a distict "assign function pointer" operator should be required.
Algol-60's "call by name" seems far more useful and less problematic and even that used to trip people up a lot. At least a lot of compilers had the option to flag its use in order to help debug misbehaving code.
-
Sep 28th, 2022, 02:59 PM
#13
Re: Partial function in VB6?
Originally Posted by wqweto
To understand currying you have to have first-class functions in the language i.e. being able to assign functions to variables like Dim a As Variant : a = MyFunction is not available in VB6.
If one really wants to go there, then "doing it the VBScript-way" is certainly feasible:
...by defining a Class with a single default-method in it...
E.g. a Sum(Func)-Definition in a Class, named Sum:
Code:
Public Function Ret(ParamArray Args()) '<- set the Default-Attribute on this method
Ret = Args(0) + Args(1)
End Function
TestCode:
Code:
Sub Main()
Dim Sum As New Sum
Debug.Print Sum(1, 2), Sum(2, 3)
End Sub
A simple "Currying-demo" then requires only an additional Class, named SumCurried:
Code:
Private f As New Sum, m
Public Function Ret(Arg) '<- set the Default-Attribute on this method
If IsEmpty(m) Then
Set Ret = Me
m = Arg
Else
Ret = f(m, Arg)
m = Empty
End If
End Function
TestCode:
Code:
Sub Main()
Dim Sum As New Sum
Debug.Print Sum(1, 2), Sum(2, 3)
Dim CurriedSum As New SumCurried
Debug.Print CurriedSum(1)(2), CurriedSum(2)(3)
End Sub
Olaf
-
Oct 4th, 2022, 05:05 AM
#14
Banned
Re: Partial function in VB6?
Partial methods enable developers to insert custom logic into code. Typically, the code is part of a designer-generated class. Partial methods are defined in a partial class that is created by a code generator, and they are commonly used to provide notification that something has been changed. They enable the developer to specify custom behavior in response to the change.
-
Oct 4th, 2022, 05:43 AM
#15
Re: Partial function in VB6?
Originally Posted by mmarkgilbert
Partial methods enable developers to insert custom logic into code. Typically, the code is part of a designer-generated class. Partial methods are defined in a partial class that is created by a code generator, and they are commonly used to provide notification that something has been changed. They enable the developer to specify custom behavior in response to the change.
True but OP is not about partial *methods* per se. Did you read the thread?
cheers,
</wqw>
-
Oct 4th, 2022, 07:33 AM
#16
Re: Partial function in VB6?
Originally Posted by wqweto
True but OP is not about partial *methods* per se. Did you read the thread?
cheers,
</wqw>
Don't bother with this user. If you look at all of their most recent posts, they are straight copy/paste jobs of content from other websites, so I would assume this is some sort of bot.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|