473,785 Members | 2,842 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 #1
13 4394
"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. It would probably
involve writing machine code directly, and you really don't want to do
that unless you absolutely must. Note that "absolutely must" includes
"cannot possibly use a language which is better suited for this; at a
pinch, even using Clipper will be better than munging your own code
space."

Richard
Nov 14 '05 #2
Well there is no facility in C language for this. Well if you want to
create something like this you can try ony way that is giving a feel
that actually you are creating a function at run time but in actual you
dont...You take input and parse the input yourself and the if a
statement like this is there::
printf("hello world")
then make it str="hello World";
and puts(str);

Nov 14 '05 #3
"DeltaOne" <sh**********@w ipro.com> writes:
Well there is no facility in C language for this. Well if you want to
create something like this you can try ony way that is giving a feel
that actually you are creating a function at run time but in actual you
dont...You take input and parse the input yourself and the if a
statement like this is there::
printf("hell o world")
then make it str="hello World";
and puts(str);

<OT>
.... or your process writes the C text to a file, spawns other
processes to compile and link the C, then dynamically load the resulting
shared object into the running process, if your operating system
supports it.
</OT>

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


Probably by implementing a Lisp interpreter in C.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #5
Keith Thompson <ks***@mib.or g> writes:
"invincible " <mo**********@i n.bosch.com> writes:
hi friends , how can I declare / create function during runtime similiar to
lambda in lisp.
Probably by implementing a Lisp interpreter in C.


or a C interpreter in C:

http://www.softintegration.com/products/chstandard/

--
Chris.
Nov 14 '05 #6
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.

--
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 #7
Chris McDonald wrote:
"DeltaOne" <sh**********@w ipro.com> writes:
Well there is no facility in C language for this. Well if you want to
create something like this you can try ony way that is giving a feel
that actually you are creating a function at run time but in actual you
dont...You take input and parse the input yourself and the if a
statement like this is there::
printf("hel lo world")
then make it str="hello World";
and puts(str);


<OT>
... or your process writes the C text to a file, spawns other
processes to compile and link the C, then dynamically load the resulting
shared object into the running process, if your operating system
supports it.
</OT>


Or you embed a C interpreter written in standard C in your program.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 14 '05 #8
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. Then you're creating _another_
programming environment within the larger program, the language of which
may be deceptively similar to the one your main program is written in.
AFAIAA all lambda functions in all Lisp-alikes create new functions as a
part of the main program itself.

Richard
Nov 14 '05 #9
Chris McDonald wrote:
Keith Thompson <ks***@mib.or g> writes:

"invincible " <mo**********@i n.bosch.com> writes:
hi friends , how can I declare / create function during runtime similiar to
lambda in lisp.


Probably by implementing a Lisp interpreter in C.

or a C interpreter in C:

http://www.softintegration.com/products/chstandard/

www.enlightenment.org has a nice implementation of Small, a C-like
language, called Embryo.
Apparently it's very fast, and contains a small subset of C.
Nov 14 '05 #10

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

Similar topics

22
2762
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
3193
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
8869
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
1795
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
26517
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
7377
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
9480
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,...
0
10330
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10093
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
9952
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...
1
7500
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
6740
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
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.