Search Results

Search found 27 results on 2 pages for 'kernighan and ritchie'.

Page 1/2 | 1 2  | Next Page >

  • Kernighan & Ritchie word count example program in a functional language

    - by Frank
    I have been reading a little bit about functional programming on the web lately and I think I got a basic idea about the concepts behind it. I'm curious how everyday programming problems which involve some kind of state are solved in a pure functional programing language. For example: how would the word count program from the book 'The C programming Language' be implemented in a pure functional language? Any contributions are welcome as long as the solution is in a pure functional style. Here's the word count C code from the book: #include <stdio.h> #define IN 1 /* inside a word */ #define OUT 0 /* outside a word */ /* count lines, words, and characters in input */ main() { int c, nl, nw, nc, state; state = OUT; nl = nw = nc = 0; while ((c = getchar()) != EOF) { ++nc; if (c == '\n') ++nl; if (c == ' ' || c == '\n' || c = '\t') state = OUT; else if (state == OUT) { state = IN; ++nw; } } printf("%d %d %d\n", nl, nw, nc); }

    Read the article

  • What are the options for setting up a UNIX environment to learn C using Kernighan and Richie's The C Programming Language?

    - by ssbrewster
    I'm a novice programmer and have been experimenting with Javascript, jQuery and PHP but felt I wasn't getting a real depth of understanding of what I was doing. So, after reading Joel Spolsky's response to a question on this site (which I can't find now!), I took it back to basics and read Charles Petzold's 'Code' and am about to move onto Kernighan and Richie's The C Programming Language. I want to learn this in a UNIX environment but only have access to a Windows system. I have Ubuntu 12.04 running on a virtualised machine via VMWare Player, and done some coding in the terminal. Is using a Linux distro the only option for programming in a UNIX environment on Windows? And what are the next steps to start programming in C in UNIX and where do I get a compiler from?

    Read the article

  • "The C Programming Language" question about quote in the preface

    - by kurige
    From the preface of the second edition of Kernighan and Ritchie's "The C Programming Language": As before, all examples have been tested directly from the text, which is in machine-readable form. That quote threw me for a loop. What exactly does it mean? Was the original manuscript written as a literate program? My first thought was that this book, published in 1988 (original, first edition in 1978) predates literate programming, but now I'm not so sure. Can anybody shed some light on this?

    Read the article

  • "The C Programming Language" interesting quote in the preface

    - by kurige
    From the preface of the second edition of Kernighan and Ritchie's "The C Programming Language": As before, all examples have been tested directly from the text, which is in machine-readable form. That quote threw me for a loop. What exactly does it mean? Was the original manuscript written as a literate program? My first thought was that this book, published in 1988 (original, first edition in 1978) predates literate programming, but now I'm not so sure. Can anybody shed some light on this?

    Read the article

  • C Programming Language and UNIX Pioneer Passes Away

    According to a statement given to the New York Times by Ritchie's brother Bill, Dennis Ritchie was living alone at his home in Berkeley Heights, New Jersey, prior to his death. Richie's health had reportedly deteriorated, and his last years were made difficult by the after effects of treatments for prostate cancer and heart disease. In addition to his brother Bill, Ritchie is survived by his sister Lynn and his other brother John. Dennis Ritchie was born in Bronxville, New York, in 1941. His father was an engineer with Bell Labs and his mother was a homemaker. His family eventually moved...

    Read the article

  • How do I copy packages within a PPA from one release to another? (nonsensical "same version already has published binaries" error)

    - by Scott Ritchie
    I keep getting weird errors from launchpad when I try and copy the Maverick packages to Natty for the PPA. I select the wine1.3 package (not in Ubuntu), select "copy to this PPA", and then select "rebuild the resulting binaries". This error emerges: The following source cannot be copied: wine1.3 1.3.11-0ubuntu1 in maverick (same version already has published binaries in the destination archive) I have no idea what this error means but apparently it doesn't mean there are binaries in the destination archive.

    Read the article

  • First Post

    - by Allan Ritchie
    It has been a while since I've had a blog, but I'm back into the open source dev and decided to get back into things.  I had a blog a few years back when NHibernate was infant (0.8 or something) and I was working with the Wilson ORMapper (www.ormapper.net) at the time.  Anyhow, I'm still working with NHibernate (particularily the exciting v3 alpha 1) and Castle framework. I've also written a .NET ExtDirect stack for which I'll be writing a few articles around due to its flexibility.  I decided to write yet another communication stack because all the implementations I found on the Ext forums were lacking any sort of flexibility.  So stay tuned... I'll be presenting a bunch of the extension points.

    Read the article

  • Acr.ExtDirect &ndash; Part 1 &ndash; Method Resolvers

    - by Allan Ritchie
    One of the most important things of any open source libraries in my opinion is to be as open as possible while avoiding having your library become invasive to your code/business model design.  I personally could never stand marking my business and/or data access code with attributes everywhere.  XML also isn’t really a fav with too many people these days since it comes with a startup performance hit and requires runtime compiling.  I find that there is a whole ton of communication libraries out there currently requiring this (ie. WCF, RIA, etc).  Even though Acr.ExtDirect comes with its own set of attributes, you can piggy-back the [ServiceContract] & [OperationContract] attributes from WCF if you choose.  It goes beyond that though, there are 2 others “out-of-the-box” implementations – Convention based & XML Configuration.    Convention – I don’t actually recommend using this one since it opens up all of your public instance methods to remote execution calls. XML Configuration – This isn’t so bad but requires you enter all of your methods and there operation types into the Castle XML configuration & as I said earlier, XML isn’t the fav these days.   So what are your options if you don’t like attributes, convention, or XML Configuration?  Well, Acr.ExtDirect has its own extension base to give the API a list of methods and components to make available for remote execution.  1: public interface IDirectMethodResolver { 2:   3: bool IsServiceType(ComponentModel model, Type type); 4: string GetNamespace(ComponentModel model); 5: string[] GetDirectMethodNames(ComponentModel model); 6: DirectMethodType GetMethodType(ComponentModel model, MethodInfo method); 7: }   Now to implement our own method resolver:   1: public class TestResolver : IDirectMethodResolver { 2:   3: #region IDirectMethodResolver Members 4:   5: /// <summary> 6: /// Determine if you are calling a service 7: /// </summary> 8: /// <param name="model"></param> 9: /// <param name="type"></param> 10: /// <returns></returns> 11: public bool IsServiceType(ComponentModel model, Type type) { 12: return (type.Namespace == "MyBLL.Data"); 13: } 14:   15: /// <summary> 16: /// Return the calling name for the client side 17: /// </summary> 18: /// <param name="model"></param> 19: /// <returns></returns> 20: public string GetNamespace(ComponentModel model) { 21: return model.Name; 22: } 23:   24: public string[] GetDirectMethodNames(ComponentModel model) { 25: switch (model.Name) { 26: case "Products" : 27: return new [] { 28: "GetProducts", 29: "LoadProduct", 30: "Save", 31: "Update" 32: }; 33:   34: case "Categories" : 35: return new [] { 36: "GetProducts" 37: }; 38:   39: default : 40: throw new ArgumentException("Invalid type"); 41: } 42: } 43:   44: public DirectMethodType GetMethodType(ComponentModel model, MethodInfo method) { 45: if (method.Name.StartsWith("Save") || method.Name.StartsWith("Update")) 46: return DirectMethodType.FormSubmit; 47: 48: else if (method.Name.StartsWith("Load")) 49: return DirectMethodType.FormLoad; 50:   51: else 52: return DirectMethodType.Direct; 53: } 54:   55: #endregion 56: }   And there you have it, your own custom method resolver.  Pretty easy and pretty open ended!

    Read the article

  • Destroyed user account on OS X with dscl; how to restore? [migrated]

    - by Sam Ritchie
    I was trying to create a new user on my OS X Lion machine, and somehow managed to destroy my own user's account. Here are the steps I took; hopefully someone here can recognize what I did, and maybe identify some way around this. First, I ran these commands: sudo dscl localhost -create /Local/Default/Users/elasticsearch sudo dscl localhost -create /Local/Default/Users/elasticsearch /bin/bash # mistake! sudo dscl localhost -create /Local/Default/Users/elasticsearch UserShell /bin/bash sudo dscl localhost -create /Local/Default/Users/elasticsearch RealName "Elastic Search" sudo dscl localhost -create /Local/Default/Users/elasticsearch UniqueID 503 # MY uniqueID sudo dscl localhost -create /Local/Default/Users/elasticsearch PrimaryGroupID 1000 sudo dscl localhost -create /Local/Default/Users/elasticsearch NFSHomeDirectory /Local/Users/elasticsearch The big mistake I made here was using "503", which was my user's UniqueID. Immediately my shell username changed to "elasticsearch". I fiddled around, tried to change the current user with sudo su -u sritchie, but this didn't work. On restart, only the "Elastic Search" user was available. I logged into the Lion Recovery partition and reset the root password. After logging in as root and checking on the terminal, I made the remarkable discovery that my home folder was totally empty. I deleted the elasticsearch user, but it made no difference. I don't see anything in Deleted Users either. The odd thing is that when I log in now as myself (sritchie) I can see desktop icons with previews. I can even open a few text files from the Downloads folder if I use the dock alias to Downloads. Could this data be hiding somewhere? Any help would be REALLY appreciated! Thanks, Sam

    Read the article

  • Does AWS resolve same-datacenter hostnames to 10.* addresses for different customer accounts?

    - by Scott Ritchie
    If I bring up two Amazon EC2 instances and run nslookup on one for the other's hostname, amazon will return a 10.* address. This is routable within amazon, and works just fine. But does this work between different accounts? If I use one of my nodes to nslookup a hostname belonging to another customer (but still in the same datacenter) will it resolve as a 10.* address or will it give the standard public IP?

    Read the article

  • Which reference provides your definition of "elegant" or "beautiful" code?

    - by Donnied
    This question is phrased in a very specific way - it asks for references. There was a similar question posted which was closed because it was considered a duplicate to a good code question. The Programmers FAQ points out that answers should have references - or its just an unproductive sharing of (seemingly) baseless opinions. There is a difference between shortest code and most elegant code. This becomes clear in several seminal texts: Dijkstra, E. W. (1972). The humble programmer. Communications of the ACM, 15(10), 859–866. Kernighan, B. W., & Plauger, P. J. (1974). Programming style: Examples and counterexamples. ACM Comput. Surv., 6(4), 303–319. Knuth, D. E. (1984). Literate programming. The Computer Journal, 27(2), 97–111. doi:10.1093/comjnl/27.2.97 They all note the importance of clarity over brevity. Kernighan & Plauger (1974) provide descriptions of "good" code, but "good code" is certainly not synonymous with "elegant". Knuth (1984) describes the impo rtance of exposition and "excellence of style" to elegant programs. He cites Hoare - who describes that code should be self documenting. Dijkstra (1972) indicates that beautiful programs optimize efficiency but are not opaque. This sort of conversation is qulaitatively different than a random sharing of opinions. Therefore, the question - Which reference provides your definition of "elegant" or "beautiful" code? "Which *reference*" is not subjective - anything else will most likely shut the thread down, so please supply *references* not opinions.

    Read the article

  • Why is CS never a topic of conversation of the layman? [closed]

    - by hydroparadise
    Granted, every profession has it's technicalities. If you are an MD, you better know the anatomy of the human body, and if you are astronomer, you better know your calculus. Yet, you don't have to know these more advance topics to know that smoking might give you lung cancer because of carcinogens or the moon revolves around the earth because of gravity (thank you Discovery Channel). There's sort of a common knowledge (at least in more developed countries) of these more advanced topics. With that said, why are things like recursive descent parsing, BNF, or Turing machines hardly ever mentioned outsided 3000 or 4000 level classes in a university setting or between colleagues? Even back in my days before college in my pursuit of knowledge on how computers work, these very important topics (IMHO) never seem to get the light of day. Many different sources and sites go into "What is a processor?" or "What is RAM?", or "What is an OS?". You might get lucky and discover something about programming languages and how they play a role in how applications are created, but nothing about the tools for creating the language itself. To extend this idea, Dennis Ritchie died shortly after Steve Jobs, yet Dennis Ritchie got very little press compared to Steve Jobs. So, the heart of my question: Does the public in general not care to hear about computer science topics that make the technology in their lives work, or does the computer science community not lend itself to the general public to close the knowledge gap? Am I wrong to think the general public has the same thirst for knowledge on how things work as I do? Please consider the question carefully before answering or vote closing please.

    Read the article

  • Finding minimum cut-sets between bounded subgraphs

    - by Tore
    If a game map is partitioned into subgraphs, how to minimize edges between subgraphs? I have a problem, Im trying to make A* searches through a grid based game like pacman or sokoban, but i need to find "enclosures". What do i mean by enclosures? subgraphs with as few cut edges as possible given a maximum size and minimum size for number of vertices for each subgraph that act as a soft constraints. Alternatively you could say i am looking to find bridges between subgraphs, but its generally the same problem. Given a game that looks like this, what i want to do is find enclosures so that i can properly find entrances to them and thus get a good heuristic for reaching vertices inside these enclosures. So what i want is to find these colored regions on any given map. My Motivation The reason for me bothering to do this and not just staying content with the performance of a simple manhattan distance heuristic is that an enclosure heuristic can give more optimal results and i would not have to actually do the A* to get some proper distance calculations and also for later adding competitive blocking of opponents within these enclosures when playing sokoban type games. Also the enclosure heuristic can be used for a minimax approach to finding goal vertices more properly. A possible solution to the problem is the Kernighan-Lin algorithm: function Kernighan-Lin(G(V,E)): determine a balanced initial partition of the nodes into sets A and B do A1 := A; B1 := B compute D values for all a in A1 and b in B1 for (i := 1 to |V|/2) find a[i] from A1 and b[i] from B1, such that g[i] = D[a[i]] + D[b[i]] - 2*c[a][b] is maximal move a[i] to B1 and b[i] to A1 remove a[i] and b[i] from further consideration in this pass update D values for the elements of A1 = A1 / a[i] and B1 = B1 / b[i] end for find k which maximizes g_max, the sum of g[1],...,g[k] if (g_max > 0) then Exchange a[1],a[2],...,a[k] with b[1],b[2],...,b[k] until (g_max <= 0) return G(V,E) My problem with this algorithm is its runtime at O(n^2 * lg(n)), i am thinking of limiting the nodes in A1 and B1 to the border of each subgraph to reduce the amount of work done. I also dont understand the c[a][b] cost in the algorithm, if a and b do not have an edge between them is the cost assumed to be 0 or infinity, or should i create an edge based on some heuristic. Do you know what c[a][b] is supposed to be when there is no edge between a and b? Do you think my problem is suitable to use a multi level problem? Why or why not? Do you have a good idea for how to reduce the work done with the kernighan-lin algorithm for my problem?

    Read the article

  • Making only the outer vector in vector<vector<int>> fixed

    - by Dennis Ritchie
    I want to create a vector<vector<int>> where the outer vector is fixed (always containing the same vectors), but the inner vectors can be changed. For example: int n = 2; //decided at runtime assert(n>0); vector<vector<int>> outer(n); //outer vector contains n empty vectors outer.push_back(vector<int>()); //modifying outer vector - this should be error auto outer_it = outer.begin(); (*outer_it).push_back(3); //modifying inner vector. should work (which it does). I tried doing simply const vector<vector<int>>, but that makes even the inner vectors const. Is my only option to create my own custom FixedVectors class, or are there better ways out there to do this?

    Read the article

  • Error handling in C++, constructors vs. regular methods

    - by Dennis Ritchie
    I have a cheesesales.txt CSV file with all of my recent cheese sales. I want to create a class CheeseSales that can do things like these: CheeseSales sales("cheesesales.txt"); //has no default constructor cout << sales.totalSales() << endl; sales.outputPieChart("piechart.pdf"); The above code assumes that no failures will happen. In reality, failures will take place. In this case, two kinds of failures could occur: Failure in the constructor: The file may not exist, may not have read-permissions, contain invalid/unparsable data, etc. Failure in the regular method: The file may already exist, there may not be write access, too little sales data available to create a pie chart, etc. My question is simply: How would you design this code to handle failures? One idea: Return a bool from the regular method indicating failure. Not sure how to deal with the constructor. How would seasoned C++ coders do these kinds of things?

    Read the article

  • Better way of enforcing this template?

    - by Dennis Ritchie
    Currently, I have a function template like this that converts a vector into a string (just a natural string, separating the elements with a comma): //the type T must be passable into std::to_string template<typename T> std::string vec_to_str(const std::vector<T> &vec); As you can see, this is only meant for vectors whose elements can be passed into the built-in std::to_string function (such as int, double, etc.) Is it considered a good practice to document with comments the allowed T? If not, what should I do? Is it possible to enforce this in a better way?

    Read the article

  • In JavaScript, curly brace placement matters: An example by David

    I used to follow Kernighan and Ritchie style of code formatting, but lost that habit. Not sure how may hours spent on fixing JS issues due to Allman format. Every time I feel bad whilst Visual Studio gives K&R style. Just realized the impotence of K&R style for JS. My Big thanks to David for pointing the curly brace placement issue with JS and posting such a nice article. In JavaScript, curly brace placement matters: An example span.fullpost {display:none;}

    Read the article

  • Nuggets of wisdom?

    - by Bill Karwin
    There are many quotes from famous computer scientists that have become the wisdom that guides our profession. For example: "Premature optimization is the root of all evil in programming." Donald Knuth (citing Hoare's Dictum) "Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?" Brian Kernighan And so on. My question is, what are your favorite words of wisdom about programming from someone who is not famous? Was it a friend, a coworker, or a teacher, or a family member? For example, a technical writer friend of mine said: "You can't get the right answers unless you ask the right questions." Thanks for all the contributions! The answer I selected was (a) specifically coding-related, and (b) stated by someone who is not technically famous (though he has a popular blog and a podcast and runs StackOverflow). I.e. he's no Bill Gates or Yogi Berra.

    Read the article

  • Moving from windows to linux

    - by rincewind
    I need to reconcile these 2 facts: I don't feel comfortable working on Linux; I need to develop software for Linux. Some background: I have a 10+ years of programming experience on Windows (almost exclusively C/C++, but some .NET as well), I was a user of FreeBSD at home for about 3 years or so (then had to go back to Windows), and I've never had much luck with Linux. And now I have to develop software for Linux. I need a plan. On Windows, you can get away with just knowing a programming language, an API you're coding against, your IDE (VisualStudio) and some very basic tools for troubleshooting (Depends, ProcessExplorer, DebugView, WinDbg). Everything else comes naturally. On Linux, it's a very different story. How the hell would I know what DLL (sorry, Shared Object) would load, if I link to it from Firefox plugin? What's the Linux equivalent of inserting __asm int 3/DebugBreak() in the source and running the program, and then letting the OS call a debugger? Why the hell release builds use something, called appLoader, while debug builds work somehow different? Worst of all: how to provision Linux development environment? So, taking into account that hatred is usually associated with not knowing enough, what would you recommend? I'm ok with Emacs and GCC. I need to educate myself as a Linux admin/user, and I need to learn proper troubleshooting tools (strace is cool, btw), equivalents to the ones I mentioned above. Do I need to do Linux From Scratch? Or do I need to just read some books (I've read "UNIX programming enviornment" by Kernighan and "Advanced Programming..." by Stevens, but I need to learn something more practical)? Or do I need to have some Linux distro on my home computer?

    Read the article

  • How do I create my own programming language and a compiler for it

    - by Dave
    I am thorough with programming and have come across languages including BASIC, FORTRAN, COBOL, LISP, LOGO, Java, C++, C, MATLAB, Mathematica, Python, Ruby, Perl, JavaScript, Assembly and so on. I can't understand how people create programming languages and devise compilers for it. I also couldn't understand how people create OS like Windows, Mac, UNIX, DOS and so on. The other thing that is mysterious to me is how people create libraries like OpenGL, OpenCL, OpenCV, Cocoa, MFC and so on. The last thing I am unable to figure out is how scientists devise an assembly language and an assembler for a microprocessor. I would really like to learn all of these stuff and I am 15 years old. I always wanted to be a computer scientist someone like Babbage, Turing, Shannon, or Dennis Ritchie. I have already read Aho's Compiler Design and Tanenbaum's OS concepts book and they all only discuss concepts and code in a high level. They don't go into the details and nuances and how to devise a compiler or operating system. I want a concrete understanding so that I can create one myself and not just an understanding of what a thread, semaphore, process, or parsing is. I asked my brother about all this. He is a SB student in EECS at MIT and hasn't got a clue of how to actually create all these stuff in the real world. All he knows is just an understanding of Compiler Design and OS concepts like the ones that you guys have mentioned (i.e. like Thread, Synchronization, Concurrency, memory management, Lexical Analysis, Intermediate code generation and so on)

    Read the article

  • How do I create my own programming language and a compiler for it

    - by Dave
    I am thorough with programming and have come across languages including BASIC, FORTRAN, COBOL, LISP, LOGO, Java, C++, C, MATLAB, Mathematica, Python, Ruby, Perl, Javascript, Assembly and so on. I can't understand how people create programming languages and devise compilers for it. I also couldn't understand how people create OS like Windows, Mac, UNIX, DOS and so on. The other thing that is mysterious to me is how people create libraries like OpenGL, OpenCL, OpenCV, Cocoa, MFC and so on. The last thing I am unable to figure out is how scientists devise an assembly language and an assembler for a microprocessor. I would really like to learn all of these stuff and I am 15 years old. I always wanted to be a computer scientist some one like Babbage, Turing, Shannon, or Dennis Ritchie. I have already read Aho's Compiler Design and Tanenbaum's OS concepts book and they all only discuss concepts and code in a high level. They don't go into the details and nuances and how to devise a compiler or operating system. I want a concrete understanding so that I can create one myself and not just an understanding of what a thread, semaphore, process, or parsing is. I asked my brother about all this. He is a SB student in EECS at MIT and hasn't got a clue of how to actually create all these stuff in the real world. All he knows is just an understanding of Compiler Design and OS concepts like the ones that you guys have mentioned (ie like Thread, Synchronisation, Concurrency, memory management, Lexical Analysis, Intermediate code generation and so on)

    Read the article

  • Are there any widely-agreed upon guidelines for rating your language knowledge on a scale?

    - by DVK
    The question was imagined after a co-worker was complaining for an hour about some guy who could not answer basic Java questions on an interview after self-identifying himself as "8 out of 10" on Java. While that was an obvious fib, I personally always had major trouble defining my specific language skills on a sliding scale unless I'm given specific guidelines (remember 40 standard libraries by heart? Able to solve 10 random Project Euler problems in <30 mins each? Can write implementation of A, B and C data-structures from scratch in 30 mins? Know 30% of standard? Can answer 50% of questions on StackOverflow pertaining to the language?) So, I was wondering - is there some sort of commonly accepted methodology for translating such tangible benchmarks into "rate yourself on a language between 1-10"? "Kernighan gets an A, God gets a B, everyone else gets C and less" type jokes are not helpful :)

    Read the article

  • LaTeX: Left aligning without extra space between words in tables

    - by goldfrapp04
    Here is the illustrating code: \documentclass[letterpaper, 10pt]{article} \usepackage[margin=1in]{geometry} \usepackage{array} \usepackage[none]{hyphenat} \begin{document} \begin{center} \begin{tabular}{|m{4.5cm}|m{1.2cm}<{\centering}|m{8cm}|c|} \hline \centering \textbf{Course Name} & \centering \textbf{Date} & \centering \textbf{Textbook} & \centering \textbf{Grade} \tabularnewline \hline C Programming Language \& Lab & 09/2009 - 12/2009 & Brian W. Kernighan, and Dennis M. Ritchie, \textit{The C Programming Language}, 2nd ed. ISBN:9780131103627 & 89 \\ \hline Integrative Practice on Courses & 07/2011 & LUPA, \textit{Linux Software Engineer}, ISBN:9787030199645 & 87 \\ \hline \end{tabular} \end{center} \end{document} As shown in the pdf generated, there are too much space between some words because I disabled automatic hyphenation. I'd like to leave only single space between words, without justify align. THANK YOU!

    Read the article

  • byte-sized bit pattern in C and its relevance?

    - by Nikunj Banka
    I a reading Kerninghan and Ritchie's C programming language book and on page 37 it mentions byte sized bit patterns like : '\013' for vertical tab . '\007' for bell character . My doubts : What is byte sized in it and and what's a bit pattern ? What relevance does this hold and where can I apply it ? Is it in any sense related to escape sequences ? I can't seem to find any information what so ever about these byte sized bit patterns on the web . please help . thanks .

    Read the article

1 2  | Next Page >