473,796 Members | 2,690 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

create function at runtime

hi friends , how can I declare / create function during runtime similiar to
lambda in lisp.

thanks

Mohan
Nov 14 '05
13 4395
"invincible " <mo**********@i n.bosch.com> wrote:
# hi friends , how can I declare / create function during runtime similiar to
# lambda in lisp.

One way is to write the function to a file; call a compiler using system("cc ....")
to write a .so or .dll or .dylib or some other operating system specific format;
and then use operating system specific dynamic linking libraries to load it into
your address space.

Another way is to malloc a byte vector and then store the machine instruction code
in the vector. You then convert the data vector address to a function address and
call the function. However function addresses are not always the same as a data
address and you may need to combine a system specific linkage address to the code
address to get a function pointer. Also if you're using virtual memory, this would
often get a page protection fault unless you change the page characterisitic s
in a system specific fashion.

Another possibility is to use an interpretter, perhaps a threaded interpretter.
Threaded interpretters are fast and once you have the internal interpretter written
(or simply find a Forth implementation written in C), easy to do. Threaded
interpretters don't run afoul of vm page protections.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
OOOOOOOOOO! NAVY SEALS!
Nov 14 '05 #11
On Thu, 19 May 2005 09:07:53 GMT, in comp.lang.c ,
rl*@hoekstra-uitgeverij.nl (Richard Bos) wrote:
Mark McIntyre <ma**********@s pamcop.net> wrote:
On Thu, 19 May 2005 06:29:33 GMT, in comp.lang.c ,
rl*@hoekstra-uitgeverij.nl (Richard Bos) wrote:
>"invincible " <mo**********@i n.bosch.com> wrote:
>
>> hi friends , how can I declare / create function during runtime similiar to
>> lambda in lisp.
>
>You cannot. Not in ISO C, anyway; and not in any dialect of C that I'm
>aware of without resorting to the most hairy of hacks.
You could write an interpreter, and your C programme could write the
fn out to file / into memory, invoke the interpreter on it, and
process the results.


Sure, but that's a whole different thing.


He said he wanted to create a function during runtime, the above meets
the requirement. YMMV.
Then you're creating _another_ programming environment within the larger program,
So what? He didn't say this was forbidden.
the language of which may be deceptively similar to the one your main program is written in.
Again, so what?
AFAIAA all lambda functions in all Lisp-alikes create new functions as a
part of the main program itself.


I've no clue about lisp, you may be right, but IMO its irrelevant.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 14 '05 #12
Mark McIntyre <ma**********@s pamcop.net> wrote:
On Thu, 19 May 2005 09:07:53 GMT, in comp.lang.c ,
rl*@hoekstra-uitgeverij.nl (Richard Bos) wrote:
Mark McIntyre <ma**********@s pamcop.net> wrote:
On Thu, 19 May 2005 06:29:33 GMT, in comp.lang.c ,
rl*@hoekstra-uitgeverij.nl (Richard Bos) wrote:

>"invincible " <mo**********@i n.bosch.com> wrote:
>
>> hi friends , how can I declare / create function during runtime similiar to
>> lambda in lisp.
>
>You cannot. Not in ISO C, anyway; and not in any dialect of C that I'm
>aware of without resorting to the most hairy of hacks.

You could write an interpreter, and your C programme could write the
fn out to file / into memory, invoke the interpreter on it, and
process the results.


Sure, but that's a whole different thing.


He said he wanted to create a function during runtime, the above meets
the requirement. YMMV.


He said he wanted it to be similar to lambda-functions in Lisp. I'm not
a Lisp expert, but TTBOMK Lisp lambda functions are fully functional
functions, equivalent to compile-time functions in all regards except
their time of creation. In C terms this would imply, for example, being
able to pass its address to qsort() and getting the right results.

Richard
Nov 14 '05 #13
On Fri, 20 May 2005 08:13:40 GMT, in comp.lang.c ,
rl*@hoekstra-uitgeverij.nl (Richard Bos) wrote:
Mark McIntyre <ma**********@s pamcop.net> wrote:

He said he wanted to create a function during runtime, the above meets
the requirement. YMMV.


He said he wanted it to be similar to lambda-functions in Lisp.


IME 'similar to' doesn't mean 'identical to' but YMMV. Anyhoo, we're
approximately in agreement I suspect.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >
Nov 14 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
2763
by: nobody | last post by:
hello everybody, is there a way of creating an array with help of a function that would accept the name of this array as a parameter and then create global Array type variable of that name? so that for example the following code would work as well in browsers as under Windows Scripting Host: str = "tableA";
5
1940
by: invincible | last post by:
hi friends , how can I declare / create function during runtime similiar to lambda in lisp. thanks Mohan
8
3194
by: Steve Neill | last post by:
Can anyone suggest how to create an arbitrary object at runtime WITHOUT using the deprecated eval() function. The eval() method works ok (see below), but is not ideal. function Client() { } Client.prototype.fullname = "John Smith"; var s = "Client"; eval("var o = new " + s + "();"); alert(o.fullname);
3
9146
by: takarimasu | last post by:
How can i create an input object (text area,select) at runtime ? B.
7
8873
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I want my users to be able to select a report, click on a command button on a form, which will then automatically create the report as a pdf file and save it to the user's machine. I am using Adobe Acrobat (5.0 I think) and have Adobe Distiller as a
3
1797
by: leon | last post by:
hello friends, i am writing a page aspx and creating controls dinamicaly and then i must to create for each control the events as well. Anybody to know how????? happy day lion
15
26518
by: Amit D.Shinde | last post by:
I am adding a new picturebox control at runtime on the form How can i create click event handler for this control Amit Shinde
5
7378
by: Lance | last post by:
I need to create a Drawing.Bitmap from an array of integer values. My current technique creates a bitmap that eventually becomes corrupt (i.e., the bitmap's pixels change to a different color after a while). Can somebody please tell me what I'm doing wrong? Here is a sample: Public Shared Function CreateBitmapFromArray( _ ByVal width As Integer, _ ByVal height As Integer, _ ByVal pixelFormat As Drawing.Imaging.PixelFormat, _
6
1937
by: py_genetic | last post by:
Is this possible or is there a better way. I need to create a new class during runtime to be used inside a function. The class definition and body are dependant on unknows vars at time of exec, thus my reasoning here. class PosRecords(tables.IsDescription): class A(object): self.__init__(self, args):
0
9527
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10172
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.