[ art / civ / cult / cyb / diy / drg / feels / layer / lit / λ / q / r / sci / sec / tech / w / zzz ] archive provided by lainchan.jp

lainchan archive - /λ/ - 17659



File: 1469842224589.png (1 MB, 230x300, conventional.png)

No.17659

This is the Beginner's General for beginner's questions.

If you have a simple question and a suitable thread doesn't already exist, just post it here and someone will probably try to answer it for you.

Remember to do some research before asking your question. No one wants to answer a question that a simple search can already resolve.

  No.17660

File: 1469843878394.png (40.52 KB, 164x200, 1450416724595.jpg)

First question?
If I'm learning sicp should I...

1. Use MIT/GNU scheme with the edwin editor.
1.a. Use Xquartz (this is what I'm doing right now).
1.b. Install Xcode and use the homebrew installation.
2. Use Racket.
2.a. minimal racket
2.b. full racket
3. Customize emacs and use this: http://web.mit.edu/6.945/dont-panic/#sec-3-1
3.a. Install emacsformacosx
3.b. Use the command line emacs 22.
4. Another scheme dialect, or some other editor or method.

Right now I'm using method 1.a, but I can't really use it from the command line.
Also, I'm not sure how to customize anything in edwin. I think it's partly due to edwin being more limited than emacs, and my lack of experience with emacs or edwin.
For example, I don't know how to create a left-sided margin in my xterm window.
When I split the screen vertically and type past the window, I can't see the any of the text past it.
I don't know how to install themes.
I also can't highlight text.
And also, I want to clear my repl when I move onto a new file, but I'm not sure what to do there. If I want to work with repl with no definitions, I have to

A lot of these things are probably possible to do with edwin and it's probably due to my own incompetence. For example, I asked a question in the last thread about “Edwin workflow” and found answer by reading the documentation for 2 seconds.
But others might be more difficult to solve, such as cosmetic fixes. Also, I probably won't use edwin after this book, whereas the other options will probably be useful later on in different ways.

I think that learning racket and emacs would be good, but I think I would need to customize them to go through sicp. Racket would probably be easier.
I feel as it would be harder to customize edwin to fit my needs, but it is probably possible.
I could also install xcode, but part of me wants to avoid it. I'm not sure I'll use it completely. Furthermore, it isn't completely libre and I don't like the whole "apple developer" bullshit

What would you guys recommend? What would you say are the benefits of some of the actions?

Also, thank you to the guy who answered my question about the banach fixed-point theorem in the last thread (ex 1.45).

  No.17661

>>17660
Dr.Racket is a good editor, and the sicp mini-language (really just a few keywords that they use in the book, since some of the expressions are different in newer schemes) is nice.

https://www.youtube.com/watch?v=IwpnDJ45yLA
Is a video showing the stuff Dr.Rackert can do. It's definitely not for big things, but you won't be doing big things yet anyway.

  No.17724

>>17721
Why not (with tabs instead of spaces):
char hello = "Hello";
int i = 2;
int z = i*3;

  No.17745

>>17659
I'm really getting into trees right now, but the way I do it seems clumsy. Is there any good literature? Mainly I am interested in k-nary trees, for example to parse html and build a dom tree.

  No.17772

I am trying to do Exercise 1.14 in SICP.

> Exercise 1.14: Draw the tree illustrating the process generated by the count-change procedure of Section 1.2.2 in making change for 11 cents. What are the orders of growth of the space and number of steps used by this process as the amount to be changed increases?


Here is the function :
(define (count-change amount) (cc amount 5))
(define (cc amount kinds-of-coins)
(cond ((= amount 0) 1)
((or (< amount 0) (= kinds-of-coins 0)) 0)
(else (+ (cc amount
(- kinds-of-coins 1))
(cc (- amount
(first-denomination
kinds-of-coins))
kinds-of-coins)))))
(define (first-denomination kinds-of-coins)
(cond ((= kinds-of-coins 1) 1)
((= kinds-of-coins 2) 5)
((= kinds-of-coins 3) 10)
((= kinds-of-coins 4) 25)
((= kinds-of-coins 5) 50)))

To compute the complexity, I have followed this reasoning :
Complexity(count-change n) = Complexity(cc n 5)

Complexity(cc 0 k) = O(1)
Complexity(cc n k) = Complexity(cc n (k-1)) + Complexity(cc (n - annoying_value) k)

Worst case is that annoying_value==1, so :
Complexity(cc n k) = O(Complexity(cc n (k-1)) + Complexity(cc (n-1) k))

I recognize a binomial expansion (à la Pascal's Triangle), therefore :
Complexity(cc n k) = O((n+k)!/(n!k!))

And so the complexity of count-change is :
Complexity(count-change n) = O((n+5)!/(n!5!)) = O(n^5)

Thoughts?

  No.17773

File: 1470335850565.png (4.85 MB, 200x200, Introduction_to_algorithms.pdf)

>>17745
something like that book?

  No.17774

>>17745
This is overkill, but have you considered reading The Art of Computing Programming by Donald Knuth?

>>17772
It looks alright to me. Have you considered writing a tail-recursive version?

  No.17775

>>17774
>Have you considered writing a tail-recursive version?
(define (empty a b) 0)
(define (add_array array a b value)
(lambda (x y) (if (and (= a x) (= b y)) value (array x y))))

(define (count-change amount) (cc amount 5))

(define (first-denomination kinds-of-coins)
(cond ((= kinds-of-coins 1) 1)
((= kinds-of-coins 2) 5)
((= kinds-of-coins 3) 10)
((= kinds-of-coins 4) 25)
((= kinds-of-coins 5) 50)))

(define (cc amount kinds-of-coins)
(cond ((= amount 0) 1)
((or (< amount 0) (= kinds-of-coins 0)) 0)
(else ((loop empty 0 0 amount kinds-of-coins) amount kinds-of-coins))))

(define (loop array a b alim blim)
(cond ((and (= a (+ 1 alim)) (= b blim)) array)
((= a (+ 1 alim)) (loop array 0 (+ 1 b) alim blim))
(else (loop (step array a b) (+ 1 a) b alim blim))))

(define (step array a b)
(cond ((= a 0) (add_array array a b 1))
((= b 0) (add_array array a b 0))
(else (add_array array a b (+ (if (< a (first-denomination b)) 0 (array (- a (first-denomination b)) b)) (array a (- b 1)))))))

The way I implemented arrays is awful but whatever.

  No.17777

File: 1470345872316.png (29.01 KB, 200x140, Jack_black.jpg)

Is there any better feeling in life than when you learn about a new programming concept? first you get the hit from it solving the immediate problem but then you are crushed with a tidal wave as you realise all the implications and new possibilities that have opened up for you. I genuinely feel physically sick when it happens.

  No.17778

>>17777
Well, i have similar feeling then I solve some complicated SICP's problem, then i laugh about how stupid I were, and mom shouts that I am out of my mind and I better shut up and so on. Yeah, great feeling, even better than orgasm, because orgasm give you next to nothing after all, solving problem give you more confidence and brain power.

  No.17779

>>17772
>Thoughts?
Your binomial recognition is a bit handwavy but the O(n^5) is correct. Graphic version: http://www.billthelizard.com/2009/12/sicp-exercise-114-counting-change.html

  No.17835

Ive been doing Project Euler problems lately and something has been bugging me, Ive done about 8 problems so far and I have relied on nested for loops for almost all of them. Nested for loops take a looooong time (even in C) for some of these problems with large data sets.

So my question is, what is the alternative? I feel quite uncreative by relying on them almost every time but I cannot see another way.

  No.17837

>>17835
I have also been doing the early eulers, and I have also found them to mostly need for loops. As far as taking a "looooong" time you need to look at ways of cutting down repititions.

for example problem 8 you can safely jump past 0's as you know the product will be 0 every time.

  No.17841

As a beginner, how do I develop the ability to recognize what programming techniques I need to use to turn a project idea into a project? I've been absolutely struggling to make this one simple idea I've had for work into a reality; it's a local search function in C# that returns some important info that currently takes a relative age to look up the way we do it now. However, the farthest I got on my own was asking the user for input; I had no idea how I was supposed to organize the data I had so that I could retrieve it. Someone was nice enough to spend time and show me how he would have done such a thing, but I feel awful because I had no idea what to search for online and was unable to come up with even a wrong answer on my own. Even now after his help, I'm still stuck on how to perform a more complicated search (bring back results based on two different inputs) and store more of the required information without making the end result look ridiculous.

Have I run into a project that's simply out of the current scope of my ability? Should I have read something like Intro to Algorithms before I decided to jump into something like this? People I know online have said it's an easy task but it certainly doesn't feel easy.

  No.17842

>>17841
It generally helps to be able to define the problem and identify the information you need to resolve it, before you start writing the program. I like to write the problem in pseudocode before attempting to implement it, for instance.

It would help to know the specifics of the problem. If you are having some trouble searching through a particular dataset, ask yourself how you could organize this data to maximize the efficiency of the search algorithm? Sometimes sorting the data in numerical or alphabetical order can work wonders or maybe you could implement a hash table?

Sometimes jumping into the deep end of the pool is the best way to learn how to swim, I have certainly learned quite a bit by getting in over my head. Im sure you can do this. Look at the problem again, sleep on it, implement a "test" function that handles a less complex, smaller dataset and slowly add more layers of complexity, try to break it, etc.

  No.17843

>>17842
>It generally helps to be able to define the problem and identify the information you need to resolve it, before you start writing the program.
I might need more, but I just needed input from the user in the form of state and county and (maybe?) three data structures to store 40ish of the states in the US, all of the counties in each state, and then all of the towns in each county.

>how you could organize this data to maximize the efficiency of the search algorithm?

I actually do not know a single thing about this, which is why I think it's too out of the scope of my ability. All I know is that I can store and access things in lists/arrays/hashmaps; I actually learned I can treat x number of lists like a relational database from this and I guess I could use that for something much smaller.

>It would help to know the specifics of the problem.

At work (insurance), the underwriters rate property locations based on something called a protection class code, which is pretty much a fire department giving a number rating on how well-equipped the town is for fighting fires. I dunno how the scale exactly works but I know the way that the underwriters and the data entry monkeys look up this code is super archaic; I figured that since I was actually getting pretty far in this whole "self-teaching" thing (wasn't a CS/STEM major at university), I could make a little lookup program that would launch quickly and spit out the protection code instead of people having to go cell hunting for it on an excel spreadsheet just to put it on another spreadsheet.

Most of this I didn't even write myself. At first I had three nested dictionaries and was stuck on how to loop through them until I got help and I didn't even know why what he wrote worked at first (I still don't get part of it): https://ghostbin.com/paste/2g7g5

Right now that segment returns towns based on the input of the county. All I know is that I'm already seeing other problems like how I'm going to store ALL of that data, and the fact that different counties can share similarly named towns since I don't know how to search by state to filter into all of the counties in one state.

  No.17855

What would be the best way to learn about GNU autotools, is a tutorial like this (https://www.youtube.com/watch?v=tku2h_fPxhc) necessary to understand them, or can I just go "info autoconf automake libtool".
I've heard bad things about the readability of GNU's documentation so I'm not sure how to go about this.

  No.17856

>>17855
When I needed to dive into autotools I just read the documentation. Granted, I wasn't trying to do anything particularly fancy, but it was alright, and the system as a whole far less complicated than I thought.

My general impression of autotools is that because it's slightly weird, people don't bother to learn it, and so you just get these huge cargo-culted autoconf scripts that nobody really understands and do far too much. If you just write what you need, it can be very clear.

  No.17860

I know all the shit about conditions, functions, loops and all the entry level jackshit you have in every single newbie starting kit and I want to start into the deep stuff through SICP, but it has been a few years since I've concluded high school and I can't even remember about trigonometric functions or what is their purpose.

What math background do I need to have in order to be able to get through all of SICP, as a MIT student would? Is there a book that covers it all? How far the math needed for it goes?

  No.17861

anonymous$ cat test.ml
let () = print_endline (string_of_float (Unix.time ()));;

anonymous$ ocamlbuild test.native
+ /usr/bin/ocamlopt.opt test.cmx -o test.native
File "_none_", line 1:
Error: No implementations provided for the following modules:
Unix referenced from test.cmx
Command exited with code 2.
Compilation unsuccessful after building 4 targets (3 cached) in 00:00:00.

welp
I have reinstalled ocaml, and I have tried to compile it on two laptops (ArchLinux and Linux Mint), and it doesn't work.

  No.17862


  No.17874

1) If a node in a binary tree has 2 children, and we delete that node, what will replace it?
My guess is that the next biggest node on the same level will be the successor.

2) How many replacements are needed to sort 5,1,6,2,4 with ascending bubble sort?
I am guessing 7 or 5.

3) If we wanted for both postorder and preorder traversal to have the same output while traversing a binary tree, how many nodes can we have in that binary tree at the most?
I think we can have at most 1 node in such a binary tree.

4) Which operations are more efficient in doubly linked lists when compared with singly linked lists?
Is it Delete and insert perhaps?

5) The special key which is put at the end of an array is called?

6) The presentation of a data structure in memory is known under which name?

I need those for an entrance exam. I am not very interested into programming though, I prefer administration really. But the real problem is that I never had anything similar to this in my previous education. I tried googling for all of this but with little success.

  No.17875

>>17860
You don't need much. The first chapter is the most math-heavy but it's still pretty basic. You should look up differentiation though.

  No.17876

>>17860
You won't need too much math for most of it. Just read what you can and learn what you need as it comes. You can always come back to difficult topics later.

You will probably feel best knowing some Calculus beforehand, so just brush up on that and trigonometry if you feel you need to.

It's been a while since I've read SICP, but I believe this is fairly good advice.

>>17874
>1) If a node in a binary tree has 2 children, and we delete that node, what will replace it?
>My guess is that the next biggest node on the same level will be the successor.
If a node has no children, it's simply gone.
If a node has one child, it's replaced by the child.
If a node has two children, you pick one node to become the new node and then must organize the other node with respect to this new parent.

>2) How many replacements are needed to sort 5,1,6,2,4 with ascending bubble sort?

>I am guessing 7 or 5.
5 1 6 2 4   0
1 5 2 4 6 3
1 2 4 5 6 2(5)

>3) If we wanted for both postorder and preorder traversal to have the same output while traversing a binary tree, how many nodes can we have in that binary tree at the most?
>I think we can have at most 1 node in such a binary tree.
What?

>4) Which operations are more efficient in doubly linked lists when compared with singly linked lists?

>Is it Delete and insert perhaps?
A singly linked list isn't more efficient for deletion nor insertion.
A doubly linked list is easier to travel or delete, for certain cases.

>5) The special key which is put at the end of an array is called?

Are you referring to C arrays? C arrays are terminated with a zero, called NULL.
You should look into counted arrays, for a better way to store arrays.

>6) The presentation of a data structure in memory is known under which name?

I don't know what you mean. You could call it the machine representation.

  No.17878

File: 1470851980008.png (28.79 KB, 159x200, 2016-08-10-123701_548x692_scrot.png)

>>17875
>>17860

Since you guys are discussing SICP and MIT's 6.001, what would you guys recommend be the "recitations"? I've been trying to figure out what it means, and it's essentially a second, smaller class about the previous lesson.

However, it wouldn't make sense to sit down and watch the video a second time. So, would anyone have a suggestion of what to do / read when recitations are recommended?

pic related: It's the course. (notice all the R##?)

  No.17879

>>17876
>A singly linked list isn't more efficient for deletion nor insertion.
This should be this:
>A doubly linked list isn't more efficient for deletion nor insertion.

  No.17880

File: 1470854839258.png (158.46 KB, 162x200, 1434507337583-2.jpg)

>>17876
I think 1) only makes sense if it's a binary search tree, in which case you would either use the biggest node in the left children or the smallest in the right.

Same for 3), so they will be the same only with a single node.

5) is a "sentinel". (C arrays don't have one, though. Strings do, but arrays themselves don't.)

I guess 6) could be non-persistent?

>>17878
I have to admit I did not watch the lectures, I've only read the book and did most of the exercises. I guess you could do the exercises instead of the recitations.

  No.17881

>>17878
is that org-mode?

  No.17882

>>17880
Thank you for the response. I did notice that 6.001 had readings, but nothing about doing the exercises. So, I'll treat them as chapter exercises.

>>17881
yes.

  No.17884

>>17841
>As a beginner, how do I develop the ability to recognize what programming techniques I need to use to turn a project idea into a project?

In general, you want to first be clear what exactly it is you want your program to do.

After that, you want to figure out how exactly to do it. Forget the program and try figuring out what steps you would need to do. Or what a data entry monkey would do. Be as specific as possible. Write some pseudocode if it helps. You don't need to necessarily think about maximum efficiency if you're a beginner, and frankly, anything a monkey manage to do, a computer program should manage to do much faster anyway.

Lastly, you actually write the code, translating the steps/pseudocode into whatever language you use.

>>17843
>At first I had three nested dictionaries and was stuck on how to loop through them
I would have had that reflex as well. If you only want to get a list of towns given the names of state and county, that should suffice. And you don't need to loop through them since it defeats the purpose of using dictionaries. Assuming the keys in your dictionaries are the names of places, and that each state contains a dictionary of counties and that each county contains a dictionary(or list) of towns, you should be able to just do something like (figure how to do it in C# yourself):
for town in states[stateName].counties[countyName].towns {
print(town.name, town.protectionClassCode)
}

In your specific case, one of the biggest problems I see is loading the data. If it's stored in Excel spreadsheets, you will need to find a library for your programming language that opens them and figure out how it works. Then you might either go through all the data and put it in your own data structure or keep it as and directly search through it depending on what's easier and more efficient in your setup.

  No.17886

>>17876
>>17880
for question 5, is 'null terminator' an acceptable enough answer?

And yes it is mostly all in the context of either C or C++.

  No.17889

>>17661
Thanks. Any thoughts on racket vs minimal racket?

  No.17902

>>17884
Thanks for the pointers. I wrote out a general outline of the steps I did for the current process since the company has had me help out the data entry people when there's a lot of stuff to send out, but I guess I have to be as accurate as possible.

I guess a follow-up question to that would be how to think language agnostically; that is, be able to translate more technical steps since I'm able to identify things like "get input from user here" but not associate things like the spreadsheet with "put data in [x data structure]". I assume that comes with practice, obviously, but there aren't a lot of targeted resources for that. I have the C# language reference from MSDN and MSDN is usually up, but I haven't seen any materials that go over "hey, here are some common/entry-level things you can do with the syntax you've just learned outside of command-line intro to algebra equation calculators"

>you should be able to just do something like (figure how to do it in C# yourself):

Yeah, I actually was able to do this a bit in Python and get it working. I was even thinking about doing the entire thing in Python because I got the hang of it real quick and py2exe is a thing, but tkinter has ancient documentation (can't exactly skip it and just start explaining CLI to people who took years to get acclimatized to basic computer functions) and the storage of all the data is an issue.

>If it's stored in Excel spreadsheets you will need to find a library for your programming language that opens them and figure out how it works

There's a Python library for that (xlrd) which I was thinking about. Two things I learned from this for C#, however, were that I could shove my data in .txt files and use LINQ with the multiple lists or I could access a local sqlite db with a sqlite .dll reference. Both sound great but I haven't figured out how to pass integers AND strings from a .txt file to a class-based list and similarly with actually accessing the sqlite db. What I also liked about doing this in C# was that I could also transition it to a WPF/Winforms GUI with some form of ease.

I'm gonna try to keep swimming out here. Thanks for responding.

  No.17990

C++ related:
1)If some method provides a part of or all the functionality needed by a constructor or another method, how do we call that?
I am guessing we call that polymorphism or a virtual function(I am not sure).

2) What are some limitations of static member functions?

  No.17993

>>17990
1) I don't get the question, but a virtual method is a method that is declared but not implemented in a (so-called virtual) class. The children classes are expected to implement this function.

For instance, a class Object could have the virtual method
virtual void show();
But classes with virtual methods can of course not be instanciated, only their children can.

And the concrete class Square: public weapon must implement this method (or else you can't instantiate it), for instance
void show() { std::cout << "I am a square!" << std::endl; }

Polymorphism is when several functions have the same name, but not the same arguments.
For instance, if you implement a Complexnumber class, you can overload the + operator, which will get you something like that:
Complexnumber operator+(Complexnumber &c1, Complexnumber &c2);

So you can use the + operator to add complex numbers as if they were normal numbers.

You can use polymorphism with templates:
template<typename T> T add3(T a, T b, T c) { return a + b + c; }

With the above function, you can call add3 with three int, or three Complexnumber, or three whatever as long as + has been overloaded for this type. The compiler will deal with it.

2) static member functions do not belong to the objects of that class, but to the class itself. static functions are like normal functions, but they can access static values of the class, and the static values of the parents of the class.
For instance, in the following code, the private static value count is unique and returned by the static function counter(), which also do not belong to any object:
class Stuff {
private:
static int count;
int value;

public:
Stuff(int n) : value(n) {count++;}
~Stuff() {count--;;}

static int counter() {return count;}
};

int Stuff::count = 0; // you can't initialize static members inside the class definition.

int main() {
Stuff a(1), b(2);

std::cout << Stuff::counter() << std::endl;
Stuff c(3);
std::cout << Stuff::counter() << std::endl;

return 0;
}

  No.17994

>>17993
oops, I meant Square: public Object

  No.18001

Hello guys, first post on Lainchan.
I will soon finish my CS Bachelor and i would like to know some advice regarding mobile device development, specially on Android.

Would you recommend jumping on the Xamarin train or stick to Java?

  No.18015

>>18001
Take a look at some of the alternative JVM languages that have sprung up, like Scala (functional), Clojure (Java-specific Lisp), and Kotlin (traditional, like C and Python), they take the pain out of working with the Java language itself.

  No.18025

>>17724
because not every editor aligns the tabspaces, and not every person sets their editor's tabstops the same.

  No.18057

File: 1471592806717.png (64.69 KB, 113x200, k8mBKtr.png)

Is this a good curriculum? Would you improve or change anything? There are more classes, but this is basically the core of it, what i expect to do within a year.

Source is MIT open courseware.
http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/

  No.18075

>>18057
>what i expect to do within a year
Dude that's not gonna happen. Give yourself much more time to learn and digest the material.

Also, I'm not sure if this is an ordered list, but certain things seem out of order. I'd do Single Variable Calculus before Differential Equations.
Also Mathematics for Computer Science before Introduction to Algorithms. If you have a strong mathematics background you could probably do it, but considering you're reviewing precalc I'm not so sure it's the best option. That class requires a good understanding of mathematical proofs to skip it.

I would check the MIT course catalog and look at some of the prerequisites for each. You don't have to follow all of them, but I'd advise it.
http://web.mit.edu/catalog/subjects.html

Maybe add "Introduction to the Theory of Computation"?

There are some classes not listed that I might take if you can find them later.
"Introduction to Inference"
"Introduction to Machine Learning"

  No.18082

>>18075
The one year expectation is because i already finished college, and i've worked for almost two years as a developer, so a lot of the stuff i can skip. But my college education was pretty bad, i didn't see a lot of essential stuff and my class didn't really know how to code by the end of it. But i imagine i'll be able to skip/understand concepts much faster. Also i'm unemployed so i spend all of my waking hours studying or taking care of my home.

I'm not rushing it though, after finishing the first term of introduction to programming, i've decided i must review basic mathematic concepts first, so i'm donig that.

Thanks a lot for your info, i'll rearrenge the classes.

  No.18084

This has probably been asked quite a bit, but what should I learn as a first programming language? I already know very basic java, I'm planning on using linux and and very interested in cyber-security if that matters..

  No.18085

>>18084
Doesn't really matter, the differences aren't important, the concepts are.

  No.18112

>>18085
So just choose one for them then.

  No.18117

>>18112
I don't think it's in my place to choose really. It's more important to find a guide/teacher/medium that works for you. Try to choose from a source (coursera, freecodecamp, khan academy, books, youtube videos, hackerrank, code eval and many others) and learn from whatever source works best for you, with whatever language they use.

  No.18120

How do you fellow lainons usually jump into a C/C++ project?

I have a hard time figuring what's going on and try to walk through the code starting from main, but that gets difficult when there are large amount of header includes. Any advice to learn a project quicker?

  No.18126

>>18120
Don't be so sequential. It's okay to start reading main(), skim the code, functions usually have meaningful or descriptive names, else the author is a moron. if you find a function whose purpose you don't understand, look it up on the local headers, just open it in a new buffer and search the name. No rocket science. They often come with a documentation comment in the headers.
Skim main(), try to make sense of it, try to map it to what you get when you run the code. If a commonly used functionality turns out to be the result of a branch (some sort of loop in some other function, for example, a REPL would be a common example), find the entry point and study that.
I remember I used to try and read every function that gets called upon sight, sequentially reading as if I was the processor. Not good idea, you can miss the forest for the trees that way.

  No.18137

>>18126
Alright thanks, I always figured you get a better idea of the flow from reading it like it would execute but it's not practical.

In particular I'm looking at the source for paludis

  No.18146

Can someone please comment on my Haskell code here: >>18132 ?

I'm posting here for visibility since the Haskell thread didn't bump.

  No.18148

I don't think this question deserves it's own thread so i'll post it here.

How many of you guys work from home? How hard is it to work in software engineering from home? Most jobs i've seen are for front end-esque positions. Rarely do i see something for actual software engineering, and i'd really like to get one.

  No.18160

>>18146
>>18132
>separateWhile f a = (takeWhile f a, skipWhile f a)
The first thing to jump out is that you are evaluating the predicate twice on each element, which is wasteful. Get a third argument into a helper function and build up the take/skip list (in reverse), then as soon as the predicate fails you have both parts at hand.

You might also consider using a parser monad.

  No.18165

Can I ask for some input on this exercise?
For some reason, this works in racket but not with mit-scheme (I used emacs and edwin).
This is the code (it seems to do what I want in racket, but if I ever join two nodes and try to print them, it gets in an infinite loop).
#lang planet neil/sicp
;;node selectors
(define (left-node node) (car (cdr node)))
(define (right-node node) (cdr (cdr node)))
(define (get-value node) (car node))
(define (set-left-node! node ptr) (set-car! (cdr node) ptr))
(define (set-right-node! node ptr) (set-cdr! (cdr node) ptr))
(define (make-node val) (cons val (cons '() '())))
(define (adjoin-nodes! lnode rnode)
(set-left-node! rnode lnode)
(set-right-node! lnode rnode))
;;deque selectors, creators, and booleans
(define (make-deque) (cons '() '()))
(define (empty-deque? deque)
(or (null? (car deque)) (null? (cdr deque))))
(define (front-deque deque)
(get-value (car deque)))
(define (rear-deque deque)
(get-value (cdr deque)))
(define (front-node deque)
(if (empty-deque? deque)
(error "FRONT-NODE called with empty deque" deque)
(car deque)))
(define (rear-node deque)
(if (empty-deque? deque)
(error "REAR-NODE called with empty deque" deque)
(cdr deque)))
;;mutators of queue
(define (set-front-ptr! deque node)
(set-car! deque node))
(define (set-rear-ptr! deque node)
(set-cdr! deque node))
(define (front-insert-deque! deque item)
(let ((new-node (make-node item)))
(cond ((empty-deque? deque)
(set-front-ptr! deque new-node)
(set-rear-ptr! deque new-node)
deque)
(else
(adjoin-nodes! new-node (front-node deque))
(set-front-ptr! deque new-node)
deque))))
(define (rear-insert-deque! deque item)
(let ((new-node (make-node item)))
(cond ((empty-deque? deque)
(set-front-ptr! deque new-node)
(set-rear-ptr! deque new-node)
deque)
(else
(adjoin-nodes! (rear-node deque) new-node)
(set-rear-ptr! deque new-node)
deque))))
(define (front-delete-deque! deque)
(cond ((empty-deque? deque)
(error "DELETE called with empty deque" deque))
(else
(set-front-ptr! deque (right-node (front-node deque)))
(set-left-node! (front-node deque) '()))))
(define (rear-delete-deque! deque)
(cond ((empty-deque? deque)
(error "DELETE called with empty deque" deque))
(else
(set-rear-ptr! deque (left-node (rear-node deque)))
(set-right-node! (rear-node deque) '()))))

I was considering a different approach that involved creating two lists. One that is the reverse of the other (they point to the same items, but start from different ends) and having four pointers, which point to the beginning and end of both lists.
Would this be a better approach.

Also, if I avoid printing the queue or adjoined nodes, it works perfectly fine.

  No.18166

>>18165
Forgot to mention, this is exercise 3.23 from sicp.
I was considering doing it in a manner similar to exercise 3.22 from sicp (making "make-deque" return a procedure called dispatch), as this might avoid the issue with infinite recursion.

**testing**
spoilers

  No.18177

File: 1472072864668.png (37.25 KB, 200x171, Ge4C4Aj.png)

>>18057
Alright, turns out i won't have enough money to finish the course before needing to get a job, so i changed the priorities a bit. Electrical engineering now is an optional section, i'll focus on mathematics and programming, and if i have the time and i'm not running out of food i'll move on to EE.

What do you guys think of this curriculum? I have 5 years of horrible programming experience (bad practices and old technologies), and i want to be a good programmer before moving on in my career.

The list is not ordered, so just worry about the content, do you guys think that is good enough to join a good company as a software engineer? (Knowledgewise, since i won't have any certificates or anything).

  No.18183

>>18165
>if I ever join two nodes and try to print them, it gets in an infinite loop
Did you miss the footnote?
https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-22.html#%_thm_3.23
https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-22.html#footnote_Temp_370
https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-22.html#call_footnote_Temp_370

When using a cons tree to build a data structure, if two cons cells are both reachable [1] from the other, you automatically get a cycle when trying to exhaustively walk the tree, such as for plain printing. Because deques require deleting from the rear, the penultimate element has to be reachable from the last one in order to become the new rear, so a cycle inevitably forms in the supporting cons tree. The solution is given by Eva in 3.21: "If you want to see the queue printed correctly, you'll have to define your own print procedure for queues". Write a print procedure for deques that walks the queue in one direction and assembles the values into a list.

>two lists

>they point to the same items
>Would this be a better approach.
No. They would contain the same values, but in different cons cells, so you would still not have a constant-time way of getting the penultimate value holder given the last one. The second node in one list would not be the same as the penultimate one in the other, they would merely contain the same value.

>>18166
>making "make-deque" return a procedure called dispatch), as this might avoid the issue with infinite recursion.
Switching to the message-passing version is a modification of the way to interact with the deque, it has no bearing on the internal structure -- the cons tree -- used to store values. If you keep the same linking setup between nodes you obviously keep the same cycles.


[1] Define a relation reachable(A,B) iff starting from A and using a sequence of car and cdr calls you can reach B, where the target test is identity (eq?).

  No.18189

>>18177
you made a pretty list instead of reading the books/doing the courses. pretty bad start i'd say. is this really what you want to do?

  No.18190

>>18189
That's pretty pretentious and completely irrelevant to the topic, dude.
I've been to college, i worked two years as a full stack programmer, but my education wasn't worth anything so i'm re-educating myself ever since i quit my job. I've been studying for the past 6 months, and only now i have enough notion of online resources to create a proper curriculum, and this list and this question is about that curriculum, if am i missing something from people who went to actually good colleges.

It's nice and good to exert elitism, but don't be a dick. I'm putting all of my hours into this, but i cannot possibly know what the advanced courses are like, or if i'm missing something important, so instead of investing my hours upon trial and error i create a fucking post and ask about it.

Sorry if my response was rude, but it's really frustating to be giving so much into something only to be treated like a 13 year old who just watched "hackers" and doesn't know what the field is like. This is not a whim, i'm not "making pretty lists", this is what i'm already doing and i wish i had the time to do all the courses that interest me but that is not possible without being homeless.

  No.18196

>>18177
the 5 years of experience counts for a whole lot more than any non accredited coursework. I would just focus on blitzing interviews and learning/brushing up on your choice of the standard "enterprise" languages.

  No.18197

Who is the dude that thought it's a good idea to invent a language where everything is between ( and )

  No.18198

>>18190
wasn't trying to be rude, display elitism, or anything like that. i've seen posts like yours before where they list all these books where even completing one would be an accomplishment (sometimes because of difficulty, others because of commitment). the point of my previous reply was to get you to start on one of those books instead of getting lainchan-approved™.

posting so you dont waste your time on something is a mixed bag. its rare to find something so awful that the majority tell you to avoid it. instead you'll get 10 responses with 10 different opinions and nothing changed.

if just getting a job is your priority there's the quick and dirty route: learn js, node, and some popular backends.

  No.18203

>>18196
>>18198
I understand, i already have experience with a few of the popular backends, but i don't really want to get a random job again. I have money for a few more months of bills so what i'm trying to do is get more experience, so i can have more confidence in my ability before progressing in my career.

At my last job i didn't learn anything since i joined the company until i left and that was pretty depressing. Since i didn't have any time to study at home and my college was worthless, i was stuck in this situation.
So my goal before trying to get another job is to study enough to know i'm growing as a professional, instead of just going to work to survive and pay the bills.
i don't mind working with JS backends, as long as i know i'm being efficient and not just hitting problems with a club until it works. That's the purpose of getting these courses, so languages become irrelevant aka my ability doesn't rely on a library.

  No.18204

>>18197
It wasn't supposed to be like this.
https://en.wikipedia.org/wiki/M-expression

  No.18205

>>18197
It's actually the best once you get used to it.

  No.18207

>>18183
>Did you miss the footnote?
yup, I'm an idiot.
Thanks for the response though. I guess rackets method of priniting avoids infinite recursion somehow.

Also, would you recommend any changes to the program?
Would you say the messaging passing is a better approach than the current one?
Should I tag everything, or is that unnecessary?

  No.18213

>>18207
>rackets method of priniting avoids infinite recursion somehow
Detecting cycles by keeping track of already visited cons cells was covered in section 3.3.1.
https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-22.html#%_sec_3.3.1
Modern Scheme implementations usually have some form of this built in.
guile> (define x '(1 2 3 4))
guile> (set-cdr! (last-pair x) x)
guile> x
(1 2 3 4 . #-3#)
You can still force the issue by asking for (last-pair x).

>Would you say the messaging passing is a better approach than the current one?

For small stand-alone programs there is no significant difference. As the program grows larger and more complex message passing becomes superior because it provides structuring and encapsulation. For example, a top-level procedure with a generic name like get-value would quickly become a headache in a large program.

>Should I tag everything, or is that unnecessary?

Tagging is a technique that is appropriate in situations where the same method needs to be able to handle, and thus has to differentiate between, arguments of various types. If such a situation does not naturally arise in the design of your program, tagging just for tagging's sake is overkill and adds needless complexity.

>would you recommend any changes

- Chains of c[ad]r calls usually have shorter forms for convenience.
https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-15.html#footnote_Temp_157
- front-deque and rear-deque are missing the empty deque test.
- front-node and rear-node are only called by your program after empty deque tests, thus their own builtin tests are wasteful duplication.
- You forgot to return deque on the else branches of deletes.

  No.18215

I'm using a free website to learn HTML, should I do PHP next or just skip to it right now? I'm about half way through with the sites HTML course.
https://www.codecademy.com/learn/web

  No.18216

>>18215
Finish HTML, you'll need it.

  No.18217

>>18216
Okay, I thought so. Thanks, Lainon

  No.18221

so im planning to learn bash and c but unable to start because i have in mind that after i learn them i dont know in what kind of cool stuff i could use them so im asking here what kind of stuff i could make if i learn bash and c

  No.18222

>>18221
anything you like, but if you are more interested in making things than just learning programming I'd suggest skipping C and learning python or golang or something like that. Otherwise you are just going to burnout pissing about with pointers and memory, not really making much.

  No.18233

>>18221
I agree with >>18222 in that if you want to get stuff done, C is not the language to go. I mean, yeah, you can make stuff, but in C it means a lot of work.
As to bash, I don't know if you want to learn tat either right now. You'll mostly be doing system maintenance/administration tasks: working with files and so on. You're pretty much limited to the stuff that you can do on your shell, though it can be a lot, it is also a very well outlined set of functionality (CVS (something like git) was first made as a set of shell scripts), you could make some simple web scrapers, a script that puts together a whole linux distribution, or an installer script, but not much outside that domain of functionality.
Anyway, I also would advise against thinking of "the cool stuff you could make", that'll come with time. For one thing, maybe you end up liking C a lot because you, like me, like to know the inner workings of unix software, or because you might like exploiting programs or reverse engineering, or you decide you want to make embedded systems or compilers. C is a very bare bones language at that.
A big part of programming is just learning the art itself. There is a lot of research going on just in designing programming languages. The irony, the languages are a tool for getting stuff done, and they end up as a very exciting area of programming itself.
Anyway, that said, if you want to learn how programming can help you expand your mind and such and such, check out a bunch of programming languages that differ from the mainstream: haskell, lisp, forth, APL. I think you'll find a lot of fun in this.
Now if you want to be h4xx0 then you do well in learning C and bash.

  No.18236

>>18222
>>18233
thanks for your reply guys
i read that C and bash can be useful for robotics, is that true?
what kind of stuff can i do in robotics with C and bash?
are there more useful languages, like specifical for robotics that i should learn?

  No.18239

>>18236
Not bash. *sh is the user interface for Unix systems.
C is what you would program those PICs in. Also look at assembly and Forth.
Have fun

  No.18275

What operating should I use as to where I can spoof my mac, only let a few connections go out, and etc.. I want complete control and for it to be as barebones as possible.

  No.18277

>>18275
You can do that with just about any OS (open source, should go wihout saying, and I assume you mean Unixes as well).
Networking is one of the things that barely if at all varies across systems (though recent linucks distributions usee a slightly different interface than the old trusty ifconfig).
That said, you only need to learn the actual networking technology in unix, and you should be okay with any distribution.
I wouldn't know if I'd trust systemd, though. But if you want things clean you've probably already discarded the D anyway

  No.18289

I've got a quick java question.

I'm wondering how to pass arguments to a function.

public class Banjo {
public static String areYouPlayingBanjo(String name) {
String nLower = name.toLowerCase();
return nLower.substring(0) == "r" ? (name + "plays banjo") : (name + "does not play banjo");
}
}

I'm trying to call this function so that the name argument is "Richard"

  No.18290

>>18289
Instance banjo, call the function with whatever parameter you want. Google the terms if you don't understand them.

  No.18295

>>18290
Got it, thanks much!

  No.18372

Do you guys also feel that reading books are a way to fixate the knowledge you already have?
For example, i remember when i first started college i tried to read "C++ primer", i couldn't do it. It wasn't a physical barrier, if i were to read it carefully and do all the exercises i would learn something, surely. But it's not effective, it's like carrying a much larger weight than you are capable of.
After i learned C++ though, reading that book again was a much better experience, i was revisiting concepts that i already knew about, but in a much more concrete way, the concepts were better fixed in my head.

How do you go about it? Can you read new concepts from a book, and form a book alone? If you were to learn assembly for the first time, could you do it from books only?

  No.18382

>>18372
I certainly believe so. I don't have a source, but I know that a very effective way to learn something is to learn it, forget it (at least partially) and learn it again. Doing so establishes long-term memory of the subject.

Could you learn assembly for the first time from a book and nothing else? I'm sure you could, but it would not be the easiest way to do it. To really learn any programming language from a book, you'd need to be diligent and do all the exercises, probably multiple times, and more importantly, you'd need to fully understand all of the concepts. If the book was in-depth enough, and you put in some serious time, I think almost all people would eventually 'get it'.

  No.18383

>>18372
I have been reading "unix network programming" to learn, I think you can guess what. I don't use it exclusively but it is good to get an explanation of what you are doing and why and anything specific or C related I use man pages and the wired.

I never learned programming general from a book though. I did have K&R as a resource but I've never "gone through it". So maybe books are good for revision and specific branches but not general knowledge.

The problem with books is they can't see your mistakes and making and fixing them is a critical part of learning. They really need to be combined with a teacher or the net.

  No.18384

>>18383
forgot to say books give a good structure for learning as well even if you don't learn from the book its self.

  No.18417

How long should i expect my system to be down for if i install gentoo right now? I'm studying very long periods of time (8h+), and i wouldn't want to be away from it for 2~3 days because my OS isn't working. On the other hand, learning CS using a VM is becoming quite bothersome, i did some research on distros and gentoo is the first one i'll install physically (i already have a VM)

I'm not asking to be spoonfed, i just want the opinion of more experienced users on how long it'd take to switch from windows to gentoo and make it run smoothly. Considering i have used computers since i remember being alive, and i'd still have internet access through a tablet.

  No.18420

>>18417
If you're experienced you can get gentoo up and running in as few as say 40 minutes.
If you're not, you can expect a couple hours downtime, varying depending on features that you might need (for example, first time I installed, I missed the wireless driver, some other time I didn't quite like the vconsole resolution and took me a while to set up... )
Details aside, 2 hours is probably the top for a simply running system without X. On the other hand if you need X, it does take a couple extra hours to compile on a 2 processor machine (in my experience).
Whatever problems you might run into, which are but a handful, the community at #gentoo is very helpful, a lot. Some of the problems I've run into at first boot have also been solved by merely doing a full upgrade, which may take about 40 minutes.

  No.18421

>>18420
Thanks a lot.

  No.18440

public class PyIntIt{

public int itInt(int n){
String strInt = "" + n;

for(int i = 0; i < strInt.length(); i++)
{
int d = Character.getNumericValue(strInt.charAt(i));
return d;
}

}
}

Is there a better way of iterating integers by character in Java? I'm pretty used to the for loops in Python and want to create something with a similar effect to that that I can just throw in a library.

  No.18441

>>18440
What are you iterating over an integer by digit by? That seems a really strange operation.

  No.18442

>>18441
Had a problem where i needed to apply an equation to every digit in an int and found that there was no concise solution other than just turning it into a string and working from there.

  No.18443

>>18442
What was the problem? I don't think I've ever needed to do that.

  No.18450

>>18440
this post made me feel the opposite of nostalgia for when I was learning Java.

  No.18452

>>18450
Same. I worked with java 6 for a year (it was last year, not when java 6 came out). It was one of the worst programming experiences i've had, the pain of dealing with date manipulation by itself already makes me feel weak and tired.

  No.18457

>>18443
Had to square every character in an integer, so 9119 would read 811181

Just some codewars stuff, I'm certain it's less practical in reality, but practicality isn't the point, I just want the ability to do soykaf .

  No.18458

>>18457
Something like this?
import java.util.Stack;

public class Digits {

public static void main(String[] args) {
Stack<Integer> source = toDigits(1234);
Stack<Integer> target = new Stack<Integer>();

for (Integer i : source) {
target.push(i * i);
}

System.out.println(fromDigits(target));
}

public static Stack<Integer> toDigits(int i) {
Stack<Integer> result = new Stack<Integer>();
while (i > 0) {
result.push(new Integer(i % 10));
i = i / 10;
}
return result;
}

public static int fromDigits(Stack<Integer> l) {
int r = 0;
while (!l.isEmpty()) {
int d = l.pop();
double length = Math.floor(Math.log10(d)) + 1;
r = r * (int)Math.pow(10, length) + d;
}
return r;
}
}

  No.18465

File: 1473133171601.png (136.12 KB, 150x200, 1444063753981.jpg)

>>18458
I dont know all of the commands listed there but it looks close enough in form to possibly be what I'm looking for. Time to decipher this and see if its the guy.

  No.18467

>>18458
This is the operation I was doing yes.

public class SquareDigit {

public static void main(String[] args){
SquareDigit obj = new SquareDigit();
obj.squareDigits(1234);
}


public int squareDigits(int n) {
String strInt = "" + n;
String finalDouble = "";
for(int i = 0; i < strInt.length(); i++)
{
int d = Character.getNumericValue(strInt.charAt(i));
finalDouble += (d * d);
}
int f = Integer.parseInt(finalDouble);
System.out.println(f);
return f;
}
}

This is how I was doing it, I (still) have no clue which is more efficient.

That being said I would like to end up in a place where I could call a function to iterate integers with whatever math operation you'd want to apply it to. I'm certain I could make a library that does this and will probably post some code once I get actual progress on it.


  No.18480

What C/C++ open source projects would be approachable for a beginner? Most answers on stack overflow only link big projects that seem like a shitty place full of elitist assholes. I've yet to try joining one, but only if i don't find something else.

  No.18487

How often do you guys use debuggers? So far in my career, which isn't much since i've never made anything over 1000 lines, i felt that using print is much more effective and clean. I see a lot of teachers saying that they only use print, and certainly that leaned me towards print, but i tried using a debugger and it's just..cluttered i guess, if i don't have the program drawn in my head enough to know what i should be looking for, a debugger won't help me, and if i do, i don't need a debugger.

Might be beginner's luck that i never encountered a problem that made a debugger necessary, but i'd like to know about you.

  No.18491

>>18487
I use Common Lisp, which requires implementations to provide their own debuggers.

I've never used a UNIX-style debugger, which mostly works at the level of machine code, however.

  No.18492

>>18468
>Lambda is ->

Fuck you java, who thought this was a good fuarrrking idea.

  No.18511

>>18487
I don't think print is clean, even the
#ifdef DEBUG
printf("[DEBUG] at function() x=%d\n", x);
#endif
all over the place I think is mostly cluttered, even if you delete them afterwards. Also it doesn't always work. Sometimes it's better to look at the raw memory at any point.
I usually include the debug symbols with "-g" so I can look at the code while I debug. Then if I have, say, that the program segfaults at a particular point, I break at that point, look at the suspicious variables, and the stack frame; identify the return address in the stack frame, and I usually break at function calls and returns; run up to where I think it should work, if it crashes I restart and take a closer look at where it seemed to crash. After a while it gets easier, and you kinda develop a sense for where things go wrong and also get used to looking at the stack frame and identifying what's near %ebp and also where the variables are stored.
Of course, I assumed here that you are using C or C++ and gdb for your debugger.

  No.18512

>>18511
I think it's all about the size of the problems i worked with. Using GDB so far seems more troublesome than just printing variables and then deleting the statement.

  No.18534

>>18512
another lain here I didn't know DEBUG was a thing.

  No.18535


  No.18543

>>18534
it's just a preprocessor symbol. Nothing built-in about it. You define it at compile time with -DDEBUG though the symbol might as well be
#ifdef HOOCHIEMAMA
...
and use -DHOOCHIEMAMA
man gcc for more information

  No.18561

File: 1473394132180.png (44.71 KB, 200x150, unnamed.jpg)

I want to make a bot (probably in python for now) which will monitor given lainchan threads and alert me somehow when a given thread updates with >=1 new post, maybe with parameters that I can set like only alert me if it's replying to a certain other post or something like that. I was looking through auto-reload.js, which is part of the site source, for something that I could monitor that would change whenever an OP gets a comment, but I couldn't find anything obvious. Does anyone know what I should be looking for/looking at? Am I going in the right direction at all?

  No.18562

>>18561
There's a JSON API.

The JSON for this thread is located here: https://lainchan.org/%CE%BB/res/17659.json

You could poll it every ten minutes or so.

  No.18649

Here is the section from SICP which explain Greatest common divisor:
The idea of the algorithm is based on the observation that, if r is the
remainder when a is divided by b, then the common divisors of a and b
are precisely the same as the cornmon divisors of b and r . Thus, we can
use the equation
GCD (a , b) = GCD (b , r)
to successively reduce the problem of computing a GCD to the problem
of computing the GCD of smaller and smaller pairs of integers. For
example,
GCD (206, 40) = GCD( 40, 6)
= GCD(6, 4)
= GCD (4, 2)
= GCD(2, 0)
=2
reduces GCD(206,40) to GCD(2,0), which is 2.

I got it.
But here is the problem, they say that this process generates an iterative process, whose number of steps grows as the
logarithm of the numbers involved.
The last part of the sentence confuses me. Why logarithmic growth? Where is the connection between involved numbers and number of steps? They don't explain this, maybe lains could help me?

  No.18650

>>18649
Let's suppose a > b, and r = a mod b. Obviously, r < a and r < b. Here '/' means the integer division (eg. 3/2 = 1).
If b ⩽ a/2, r ⩽ a/2.
If b > a/2, a/b < a/(a/2), therefore a/b < 2, so a/b = 1. Then a = 1*b+r, so r = a-b, so r < a-a/2, ie r < a/2.
In both cases, r ⩽ a/2.

In the next step of the computation, the new value of a and b (let's call them a' and b') are: a' = b, and b' = r.
In the next step of the computation, the new value of a and b (let's call them a'' and b'') are: a'' = r, and b'' = a' mod b'.
Therefore a'' ⩽ a/2. It's as if you divide a by 2 every two steps.

As a is always non-zero, you get at most 2*log₂(a) steps.

  No.18652

>>18650
> It's as if you divide a by 2 every two steps.
Doesn't it mean that its a linear growth? We divide a by 2 every two steps, we divide a by 4 every four steps,and so on. So it should be a linear growth, no?

  No.18654

>>18652
Example: GCD(89,55)
89 = 1*55+34
55 = 1*34+21
34 = 1*21+13 (89/2 = 44, we get 34)
21 = 1*13+8
13 = 1*8+5 (44/2 = 22, we get 13)
8 = 1*5+3
5 = 1*3+2 (13/2 = 6, we get 5)
3 = 1*2+1
2 = 1*1+1 (5/2 = 2, we get 2)
1 = 1*1+0


Each time, a/2 is more than the value of a two steps later.

We have 10 steps in total, and 2*log₂(89)=12.951

  No.18695

I wrote a C program that takes an integer as a command line argument and outputs its binary equivalent. The problem is my first implementation only worked for numbers under 256 but I optimized it but now it only works for numbers under 512. I having a lot of trouble optimizing it to work for all numbers. Any suggestions? Was using bitwise operations a bad idea?

int main(int argc, char *argv[]){

int decNumber = atoi(argv[1]); //convert cl arg to int
const int binSize8 = 8, binSize16 = 16;//length of binary numbers
const int byteSize = 256;//when 2 bytes are required to rep binary
const size_t size8 = 8, size16 = 16;
int counter = 0;

if (decNumber < byteSize){//if number is under 256

int *numList = calloc(size8, sizeof(int));
int binList[] = {128,64,32,16,8,4,2,1};//array of 8 bits, powers of 2

while (counter < size8){ //use bitwise & to compare number bits
numList[counter] = (decNumber & binList[counter]);
counter++;
}
switchOne(numList, binSize8);//replace nonzeros with 1's
for(int i = 0; i < binSize8; i++) //print
printf("%d", numList[i]);

free(numList);
}
else if (decNumber >= byteSize){//if number is 256 or under 512

int *numList = calloc(size16, sizeof(int));
int binList[] = {1,2,4,8,16,32,64,128,256};

while (counter < (binSize8+1)){
numList[counter] = (decNumber & binList[counter]);
counter++;
}
switchOne(numList, binSize16);
for(int i = binSize16-1; i >= 0; i--)
printf("%d", numList[i]);

free(numList);
}
else if(decNumber < 1){
printf("Error invalid input, enter positive integer.");
return 1;
}
else{ printf("Error invalid input\n"); }
printf("\n");

}//end of main

void switchOne(int array[], int size){//replaces nonzero's in an array with 1's

for(int i = 0; i < size; i++){
if(array[i] != 0)
array[i] = 1;
}
}

  No.18696

>>18695
You should check out how the shift operators work (<< and >>).

  No.18701

>>18696
Thanks I will, they are covered towards the end of the chapter Im on so I havent gotten that far yet. Probably should have waited to make a program but the idea of a binary converter popped into my head once I started learning about & and |

  No.18705

Hey, I don't have any experience at all in programming, but I'm looking to learn, with coding for games in mind. I just don't know where to start, which language to begin with.


  No.18725

>>18706
Has anyone completed or made major headway with OSSU-CS? How is it? And a related question, have employers started to consider online courses like this, edx, udacity, etc, valuable at all? Just curious if there is much point in putting it on a resume or not.

  No.18727

>>18725
I would put relevant projects that you develop during the courses, not the courses themselves. Try joining an open source project during the courses, so you can have a relevant github account by the time you finish it.

  No.18728

uint8_t buffer[64];
Why doesn't this allocate 512 bytes of memory in buffer ? If each unit of uint8_t = 8 bytes, shouldn't 64 units of uint8_t = 512 bytes?

  No.18729

>>18728
uint8_t has a width of 8 bits not bytes.

  No.18730

>>18729
Oh, thanks a lot.

  No.18769

Are there any resources for learning C++ equivalent to "Learn C the hard way" and http://www.buildyourownlisp.com/ ?

A large project that happens to teach you C++ along the way. Considering i already know C.

  No.18793

I'd like to learn programming, and I have 2 choice: sicp or this course https://courses.edx.org/courses/course-v1:MITx+6.00.1x_8+1T2016/info
Any actual difference between them?

  No.18795

>>18793
You will likely not be able to understand SICP as an introduction to programming. It's not a beginner's book.

I would recommend harvard's CS50. Take a look and decide for yourself between MIT or CS50. Both are good options, but harvard has a more broad introduction to the field.

  No.18796

I think my question can be answered with BASH scripting, but maybe not. Apologies if this isn't the right thread.

I want to download several files from a site that uses popup windows where I have to click "download" for every file, and I want to script the task. I can start the downloads and start receiving the file, is there a way to find a URL for the actual file so I can script the thing using wget? I'm thinking about some per-program network usage monitoring software but have no experience there, so I don't know if the URL I want will pop up.

  No.18799

>>18796
Your question is a bit too general so it's not possible to give you something like a command but you'd:
1 See the source for the download page
2 look for the part with the popup window, it's a javascript function so it's somewhere between <script> tags, or possibly in a .js file on it's own
3. just look t¿for the part that gets the url of the file you want to download. It might be an url for the file itself, or it might be a .php, you need to figure that out.
4. Use sed (not grep in this case, it's easier to use sed to just match the url and discard everything else with the match operator m//) to match the url of the file every time.
5. pass that url into wget

Sorry if the answer is too broad, there's little more I could do, read wget(1) and sed(1) for details (such as the flags you'd need, for example to pass the output of wget directly to sed, like curl does by default)

  No.18800

>>18796
You can script your browser with frameworks like selenium. To see the urls your browser fetches check the developer tools, such as the web console. To see all non-https get/post requests monitor your outgoing packets with e.g. tcpdump. To see https you can mitm yourself with your own proxy, such as fiddler.

  No.18801

>>18799
Thanks for the reply. Yes, I asked broadly, I think I'm missing the name of some program or some basic tool that I can look up. Even if you posted a command I didn't know I'd be reading the manpage to see how it works, so it's the same in the end.

The strings ".zip" and "php" are not in the source's text, and the javascript fetching the files looks like this
<table>
<thead>
<tr>
<th>Instant Downloads</th>
</tr>
</thead>
<tbody>

<tr>
<td><a href="#click" onclick="javascript:Store.download.show('df1e4680c97d2f8405227d1f94ad9354',104268);">Nullsleep - Hello World (mp3)</a></td>
</tr>

<tr>
<td><a href="#click" onclick="javascript:Store.download.show('df1e4680c97d2f8405227d1f94ad9354',104293);">The 8bitpeoples - The 8bits of Christmas (mp3)</a></td>
</tr>
...
That's why I thought I'd have to see the where the traffic was coming from.

>>18800
I'll take a look at palemoon's dev tools plus tcpdump and fiddler, thanks.

  No.18803

>>18801
There seems to be a Store object of sorts. Look into the rest of the JS code, trace the logic to get to where the actual content is being requested.
I know I'm not being very helpful, sorry. Also I don't really know any js, at all

  No.18804

>>18799
>>18800
>>18803
I used a dev tool that comes with Palemoon and found that the file come from amazonaws.com/.../file.zip, but wget gave me a 403 error (forbidden), even when ignoring the robots.txt. I'll still check the tools mentioned when I have some time, it'd be useful to do the same check with something lighter than a web browser. Thanks for the answers.

And yes, there was a Store object defined in a file I could retrieve, but I couldn't make sense of the definition.

  No.18806

>>18804
>gave me a 403 error (forbidden)
This is because you need to replicate the browser's request, including such things as user agent, referer and cookies. See network in dev tools for the request headers, or get the verbatim request with tcpdump.

>I couldn't make sense of the definition

If it's obfuscated you'll have to reverse engineer it, painstakingly. Chances are though that someone else already has, and posted somewhere about it.

  No.18835

File: 1474411905721.png (38.18 KB, 200x197, 1469415224986.png)

(C language)
Why do i get an error with this code

typedef struct TRIE_NODE
{
char* word;
struct TRIE_NODE node[26];
}TRIE_NODE;

but not with this one?
typedef struct TRIE_NODE
{
char* word;
struct TRIE_NODE* node[26];
}TRIE_NODE;

The error is "definition of 'struct TRIE_NODE' is not complete until the closing '}'"

  No.18836

>>18835
See http://stackoverflow.com/questions/588623/self-referential-struct-definition

The first one errors because of the attempt to refer to the typedef from inside the typedef definition.

  No.18839

>>18835
What >>18836 said, and also because the former needs
SIZE = C1 + 26 * SIZE
which is a problem, while the latter needs
SIZE = C1 + 26 * C2
which is not.

  No.18841

I want to learn this curriculum:
https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/
Any issues with that? Have someone done that already?

  No.18842

>>18841
Well..no issues. Some classes don't have videos, but most of them have a lot of material. I've done some of them.

Keep in mind that this is not a curriculum, you have to look for MIT's curriculum and make one using these classes. A bachelor curriculum isn't even 1/3 of all of these classes.

  No.18843

>>18841
I would recommend open source society if you want to be a computer scientist. You can always watch some classes from MIT (SICP is a good one).

  No.18844

>>18843
> Open Source Society
> computer-science curriculum
> no sicp in curriculum

  No.18845

>>18844
It's an alternative, you have all the freedom in the world to take the good bits and create your own curriculum if you wish to. The police won't knock down your door because you decided to study in a specific way.

  No.18851

>>18835
When you declare struct trie_node you're telling he compilers "this data ype will need this much memory".
While an array and a pointer may be equal at the symbol level, memory-wise they-re very different. A pointer is oe word size, and an array is a contiguous block of n sizeof() whatever it fits.
So you're basically thelling C to have the struct grow infinitely, in a way

  No.18860

Sorry for another silly beginner question, but could you please rate my plan:
1) SICP Chapter 1 + Basic Math from Serge
|
2) CS50+MITx's 6.00.1x
|
3)SICP Chapters 2,3,4 + Spivak's Calculus
|
4)the rest would be OSS's curriculum + this math guide from 8ch:http://hastebin.com/xepilizagu.sql + some EE courses from MIT

  No.18862

>>18860
Dude, ther is no rate, each one learns in a specific way. Do whatever you think is right, if you start on a course and it turns out to be too specialized, just go back and study more basic stuff.

Saying "10/10" won't change the fact that maybe you'll have to study to do these courses. Find your own way nobody can do that for you, in anything in life.

  No.18866

File: 1474490706971.png (7.18 KB, 200x58, 2016-09-21-153201_510x147_scrot.png)

so i have this problem:
for some reason if i multiply using a literal i get res1 = k1 + (4/2), but if multiply using an argument i get the correct result, have you ever seen something like this ?, the code is for the lm32 processor i can check my results thru simulation, as you can see in the image attached (spi_mosi), the first operation gives me 00000110 = 6 and the second one 00010100 = 20, could this be some kind of compiler optimization ? (at first i thought the multiplication operation was not supported but as you can see it works ok), sorry if this is too specific.
void spi_lcd_putchar(char c, uint8_t m)
{

volatile uint32_t res1; // uint32 is just typedef unsigned int
volatile uint32_t res2;
uint8_t k1;
uint8_t k2;

k1 = c - ' ';
res1 = k1 * 4;
spi_sendbyte(res1, 1); //this just sends the result to spi
k2 = c - ' ';
res2 = k2 * m;
spi_sendbyte(res2, 1); //this just sends the result to spi

}

int main()
{
spi_lcd_putchar('$', 4);
return 0;
}

  No.18867

>>18866
*the second one is 16, i had the example with 5 and then changed it.

  No.18870

>>18860
seconding what the other reply said. also, do you have a specific end goal in mind? thats a LOT of work for something you might be doing just for the sake of dong it.

  No.18872

>>18870
>do you have a specific end goal in mind?
sorry I should also added in my previous post, if you can answer the quoted question then it becomes easier for others to provide good criticism of your course outline.

  No.18875

I have the following structure:
typedef struct TRIE_NODE
{
char* word;
struct TRIE_NODE* node[26];
}TRIE_NODE;

And, after creating this variable:
TRIE_NODE *head = NULL;

i initialize it using this function
void initialize_node(TRIE_NODE *current_node)
{
int cont = 25;

current_node = malloc(sizeof(TRIE_NODE));

for(int i = 0; i < cont; i++)
{
current_node->node[i] = NULL;
if(current_node->node[i] == NULL)
printf("\n -- \n");
}
}

However, i get a segmentation fault in that if(current_node->node[i] == NULL), i've tried many different methods of initializing this structure, but so far i got nothing.

  No.18876

>>18875
I'm no C programmer, so take this with a grain of salt.
Why do you have the if, when it's not needed?
Aren't there standard library procedures that will zero an array for you?
Also, isn't the all-caps style generally used only for CPP macros? Wouldn't trie_node be more idiomatic and easier to write?

  No.18878

>>18876
I'm still learning C, so i'm not the best person to answer those questions. I tried initializing the whole array with {NULL} but it didn't work, so i'm manually initializing it.

  No.18880

>>18875
>if(current_node->node[i] == NULL)

TRIE_NODE->node is a pointer to an array. When you allocate the structure you're allocating just the pointer, which of course is uninitialized.

>>18876
>Also, isn't the all-caps style generally used only for CPP macros? Wouldn't trie_node be more idiomatic and easier to write?
Yes, yes it is. Of course, I'm not you're mother, but I'd suggest that you take this advice.

>Aren't there standard library procedures that will zero an array for you?

There are, do use memset() the compiler can optimize stuff.


>int cont = 25;

>for(int i = 0; i < cont; i++)
You're one off.

>void initialize_node(TRIE_NODE *current_node)

Just in case that you're not aware, if you're planning to use this function like this, it will not work:

TRIE_NODE *a;
initialize_node(a);
do_stuff(a);

  No.18881

>>18880
Thanks, i fixed the errors, now i'm sending a pointer to the pointer for initialization.

  No.18886

>>18872
> >do you have a specific end goal in mind?
Well, my goals are so blured for me right now, i just want to make my life more interesting. But I think game development/AI are the most interesting for me, and cryptography too, I spend a lot of time as a child making my own crypto-systems, and encrypted with them my diary.

  No.18889

>>18886
No point in studying mathematics unless you like it then. Follow OSS curriculum, if you feel you're lacking anything get a book. If and when you encounter mathematics, then you study mathematics.

Base your studies on necessity not on planning, you can't plan anything if you don't even know where you're going to.

  No.18896

>>18886
Then may I suggest python and C++ (soykafstorm incoming). I'm mostly choosing them (as I usually do) based on literature.
For python there are a few good introductory free books: hacking secret cypher with python, create your own games with python, and makign games with python and pygame; all by the same author.
C++ because for one thing it's the industry standard for game development (though maybe you'll want to go your own indie way), and there is a particularly good book too: programming game AI by example. There is also a book on physics for games that uses C++ I just don't remember the title.
With absolute certainty someone will now suggest lisp and I will flip Present Day, Present Time! AHAHAHAHAHA!, but honestly, CL has a very nice framework (CEPL) for making games, and it has also a great book on AI by Peter Norvig. So I'll just say beforehand: go ahead, but don't miss your goals for all the alleged lisp greatness.

  No.18898

>>18896
> Present Day, Present Time! AHAHAHAHAHA!
What is the original word for this filter? Jesus, i hate filters. Serves no purpose at all.

  No.18900

>>18898
It's that annoying "I'm just pretending to be retarded in a post-meta-ironic way" smiley face with the pointy nose.

  No.18902

I'm finishing up on CS50, as i follow open source society curriculum i also finished a few C books (Learn C the hard way, The C programming language, build your own lisp and C primer plus).

Now, i really enjoyed working with pointers, and i want to specialize in a OOP language, c++ is the way to go right? I would go for Python but i don't feel like i'm good enough with C yet to let go of pointers. Considering i'll join a few open source projects, if you were just beginning your career, would you focus on C++ or python?

I also have this fear that if my github is filled to the brim with Python projects, i'll only get web/front end opportunities. Which is probably silly, but C++ sends a clearer message.

  No.18904

>>18902
First of all: no pointers is easy than pointers. And safer. Pointers are a feast of segfaults waiting to happen, with no pointers, that just never happens.
That said, if you did enjoy working with pointers you have an advantage over all the people that dread it. And if you're anything like me, you'll never feel too much at home with high level languages.
To address your question, C++ is a logical next step after C, but there are serious pitfalls to it. For one thing you'll get bottled in the low-level von Neumman machine approach; you'll be learning the most complex language ever. And I don't mean it in a good way, I mean it in a BAD way, nobody knows C++ entirely. It's overly and needlessly complex. Also it's not proper OOP actually, it's just C with OOP badly slapped onto it. On the other hand, due to it's complexity, high paying jobs are available for C++, and they're not even that scarce.
Python... you already know it. Well, except for the OOP part. But python is literally the path of no resistance. Also everybody else knows python. However, if you do learn OOP through python, I think it's the easiest way to do it.
That said, you probably want to do some language research. For what is proper OOP, that is, OOP at it's original intention, look at Smalltalk, however Smalltalk is I believe a dead language, it's closest successor is Ruby.
But there are other approaches. Common Lisp is great in two ways: it shows how inessential OOP is, and it does wild magic beyond any other OOP implementation out there (refer to The Art of the Metaobject Protocol, Kiczales et al.)
If you decide to go down the C++ path, allow me to suggest "C++ The core language" published by O'Reilly. It is a bit dated, but it's a C++ book for C programmers that teaches the essential C++ without going into too many detail.

  No.18905

>>18902
stick it out with Python, particularly because you have a variety of projects out there already. if you want non-webmonkey work then learn Java/C#.

  No.18906

>>18905
Most java job offers i ever see are for web related projects, C# is even worse, since most of them are for windows environment. I might be wrong, so i'll do some research.

>>18904
Thanks for your input, i'll read at least one book in C++ to make up my mind, then decide between C++ or Python. I'm only available for remote jobs, so i don't think i'll ever work with C++ professionally.

  No.18938

I just finished harvard's CS50, now i'm between these two choices for my next course.
https://www.edx.org/course/how-code-systematic-program-design-part-ubcx-spd1x

https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-001-structure-and-interpretation-of-computer-programs-spring-2005/

I know a lot of you will be biased towards SICP, and i am too. But i want to learn design patterns, how to write scalable software without getting lost, as i often get in my C projects. I usually have to start from the beginning in my projects because my organization is like kicking dead whales down the beach. From MIT's description i'm not sure if their course will really teach me that or not.

Have any of you taken it, what do you think?

  No.18939

I have been out of a learning enviroment for about 5 years. Now im trying to learn how to program but I find it hard to wrap my head around programming, i followed a few courses and this some the python introduction on codeacademy. Im just not getting something. Any tips for going back to studying and maybe a pointer on a good place to build a foundation?

  No.18940

>>18939
soykaf, I ment tips for self studying


  No.18944

>>18084
I really like Python for general-purpose things and that includes Cyber Security type stuff. You can do a lot of nice things with Python. For example, check out this tutorial series for sniffing network packets.

https://www.youtube.com/watch?v=WGJC5vT5YJo&list=PL6gx4Cwl9DGDdduy0IPDDHYnUx66Vc4ed

Again, this is my own personal preference. Every language you encounter is good or better than another language depending on what you're trying to do with it. I'm only a hobbyist with programming, but I work in network/sys admin and I've just never taken the time to use the "best" language for something but use Python a lot as my preference.

  No.18945

Do any of you have any experience with mobile "app" development? A co-worker and I are looking to get our programming feet wet and make a phone application for scheduling usage of the conference room since right now, the way we keep track of it is a calendar that's shoved on some remote drive that barely anyone looks at in the first place.

My initial google search was something along the lines of "shared calendar" where we could have the application access said calendar and return all of the days the room is being used and by who, but I'm not sure if that's an efficient way to do so. Neither of us know how to start up the "big" part of the design for this.

  No.18946

>>18945
I, myself am not fully familiar with mobile development but what I do know is that much of Android is Java based for example. I just posted above mentioning how I like Python a lot, and interestingly enough it has calendar features built in.

https://www.youtube.com/watch?v=1NiXhS-d1wU

Little video here shows a sample built calendar. So from what I can grasp out of your question you could probably do something along the lines of adding conditions to meet and satisfy the days required for scheduling usage of the conference room, and relate that to who/what days its in use.

If you do look into Python I think you could easily do this part with a dictionary. Have one thing as the keys and the other as the values, since Python stores info as key/value pairs in a dictionary (other programming languages have similar features, or can be replicated).

The video I linked is very basic but I'm quite positive it could be done fairly easily to integrate into a small, easy to use mobile program. Building basic GUI's is also really straight forward with Python as well.

  No.18947

>>18945
You would be better off using an intranet page. It'd be much easier to do, and you can probably find a lot of templates.

As for a mobile app, that's a bit more complicated, since you'll have to develop for iOS, Android and windows phone. Either way look at Coursera and EDX, i'm sure you'll find free courses on these subjects.

If you're willing to pay, there are placed like treehouse that will give you courses and tutorials, but they're no better than coursera and EDX. Good luck.

  No.18948

>>18947
>You would be better off using an intranet page. It'd be much easier to do, and you can probably find a lot of templates
I was curious about how to actually plan out the big pieces for this since we don't exactly have a place where we can put an intranet page within the company infrastructure (it's complicated but the short of it is that we don't have access and it's extremely difficult to get it for reasons unbeknownst to us). I'm not curious about the specific technicalities of programming it since we'll be coming to that bridge anyhow, more the big picture in terms of where we're gonna put a calendar, or if we use something else entirely. I know we're going to be grilled about if we can "make a table in our SQL database" for it because that's our boss's new favorite word of the season.

In terms of an intranet page, I think the most web development experience the two of us have is that we both know our basic HTML/CSS, I know a tiny bit of Javascript, and he knows a tiny bit of ASP.NET; the latter probably being the path we're going to want to use since we were going to go the Xamarin route for multiplatform development.

>>18946
Python is great but it doesn't make it accessible to those whose knowledge of technology doesn't go past their smartphone. It doesn't benefit us directly in any clear way.

  No.18969

DId anyone here actually read "Build your own lisp"? I often see posts saying that you shouldn't read "Learn C the hard way", that "Build your own lisp" is a much better book.
But it's not, it might even be worse. Sure, the writer isn't a complete douchebag, but the structure of the book is exactly the same as learn the hard way books. Not only that, but "build your own lisp" is rushed, unpolished and just weak as a whole.

I read the book twice ( and many times i came back to chapter 5 because that was a mess ), and i already new C for christ sake, even knowing C and regular expressions the book is plain bad. The concepts are shallow, the writer expects no effort from the reader (even though he says otherwise).

  No.18970

>>18969
I've not read it.

I don't know why you would need regular expressions. Lisp works well with a character dispatching syntax.

If you want to learn how to build a simple language, use Forth for this. This isn't an ANSI Forth, but that doesn't matter: https://github.com/AlexandreAbreu/jonesforth/blob/master/jonesforth.S

Try reading through this. It's nice enough.

What do you actually want to do?

  No.18971

>>18795
>You will likely not be able to understand SICP as an introduction to programming
Then why MIT uses sicp as a beginner course?

  No.18972

Because it's MIT, not some random university just like you said. The beginner level in MIT's nomenclature would mean a very much advanced level for many people.

  No.18973

>>18971
It was written back when people still had a functioning attention span.

  No.18974

>>18972
Many other universities used it too:
https://mitpress.mit.edu/sicp/adopt-list.html

  No.18976

>>18974
>>18971
If you're doing a course using SICP you will be able to learn SICP because there will be someone teaching you SICP.

If you as a beginner try to learn SICP on your own you will very likely fuarrrk things up and be frustrated. Read the book for yourself and draw your own conclusions god damn it, this isn't 4chan, if you ask for advice you receive the advice and judge for yourself.

  No.18977

>>18970
>I don't know why you would need regular expressions.
The book uses it for implementation of lisp.

>What do you actually want to do?

Nothing relevant, the book just looked good and a lot of people said it was good. It's objectively a very lazily written book that i wouldn't recommend to anyone.

  No.19050

How would I find the position in a divergent series?

I have the series 1 + 2 + 3 + 4 + ... + n and pick a random number within that sequence but how to find the index? I've tried to look for a solution but most results are on the differences between convergence and divergence rather than what I need.

Could use a for loop to solve the problem i'm dealing with but am interested in how to do it mathematically.

  No.19052

I'm trying to get started with Python 3 and I came across the interactive edition of "How to think like a computer scientist". Does anyone have any experiences/opinions on that?
Picture kinda unrelated.

  No.19055

>>19050
The general term is k(k+1)/2. Set it equal to your value, solve the quadratic equation, get k. This one's straightforward because it's strictly monotonic.

  No.19118

Is it bad to mix up the courses? Right now I am going through sicp,and today I finished Chapter 1, but at the same time I wanna to start learning cs50. I'd have about 9 hours a day (3 for cs50 and 5-6 for sicp). Would it be a good plan?

  No.19119

try it and find out? especially if you are giving yourself NINE hours a day mate.

  No.19128

>>19118
You can if you want to. Do you really have the endurance to study for 9 hours straight? Or even 3 for that matter?
I mean if you can endure that much I don't see why you can't. I study a lot of things through my day, though I just do 1 hour of each.
Do give yourself a break between cs50 and scip tho, let the knowledge sink

  No.19130

>>19118
I have been studying for long periods (sometimes 14 hours/day, sometimes 6) for the past few months, and i don't think your question makes any sense.

It took me a long time to find an optimal way to study, and that's highly subjective. I've been to college, and college education doesn't work for me at all for example, i'm really good at passing tests but it doesn't mean i really learn anything. For me to learn i have to rush one content, if i'm reading a book i'll only read that book until i'm done with it, otherwise i'm spread too thin.

I don't like video classes, mostly, but a lot of people do. If you do actually have 9 hours to give in to your studies everyday, spend them figuring out how to properly study according to your preferences, otherwise you WILL be frustated and study 10 minutes before procrastinating.
It's impossible to study for so long if you're not doing it in the right way for you, it's not an anime where you just turn on a switch and study like a madman. It took me months only to find out a proper way for me to do things like that. It might take you a week or a day, but it's not something you usually know naturally.

  No.19195

I'm following the OSS curriculum, however after finishing the first course (a course by harvard, extremely high quality) i ended up in a soykafty, dumbed down course that just isn't working for me. The course is https://courses.edx.org/courses/course-v1:UBCx+SPD1x+2T2016/info, and it's a chore, i'm not learning anything from it and it's just not productive.

Thus i'm looking for a replacement for this course (the whole course, parts 1 2 and 3). Does anyone know if MIT'S SICP course is a viable alternative?

  No.19220

I need help guys. I'm semi- new to programming (familiar with the basic concepts). I used python for one semester, then java for a semester and a half(still ongoing) and currently learning mips assembly and avr assembly. I'm currently learning more advanced concepts, but i got a job at my uni doing undergrad research. The top that my mentor is looking into that i will be as well is RDMA. currently he has me learning C. What i need help with is resources/a good learning structure. I'm currently reading "practical c programming", a book i got from the book thread. My mentor said that some things i need to be familiar with as well before helping him is pthreads and shared memory. MY main issue is that, on top of C being slightly difficult to learn, a lot of these concepts are very new to me. I'm having to deal with a lot more advanced (at least in my eyes) stuff. I also have about a month to get on track and start helping him. what do lainons?

  No.19221

>>19220
CS50, first 5 weeks classes and exercises are in C, it's the best introduction you'll find. Online and free. You can easily do it in a few weeks, then drop the course when it switches do php.

Do CS50 until week 5 or 6 (can't remember, do it until they stop using C), and read a book on it while doing the course.

  No.19277

Hey there guys. I've been wanting to get into programming for a while... but /g/ and other people have kinda made me hesitant to fully dive deep into it for the following reasons:

1. How many decades will it take for me to learn to make programs that people wont complain about so much? People go on and on about good coding practices, but I only see people pointing out bad examples, not good. What resources should I study to get good enough that people will feel safe using my contributions? I'm mostly interested in programming for Linux, so I doubt people wont notice.

2. Do I have to be a genius to be a good programmer? Really, is there even such thing as a good programmer, or do /g/ and all these other elitists have their heads up their asses? People seem so devisive on what good programming is.

  No.19278

>>19277
just a clarification: by programming for linux, I mean in general. For example, I'd really like eventually get good enough to fork GTK and add a better filepicker when im selecting images on applications. The default one is a joke.

  No.19280

>>19277
>Do I have to be a genius to be a good programmer?
That's what they're claiming now? what a bunch of losers. Yeah they have their heads way up their asses, they don't even soykaf, they just re-eat the food before it even becomes soykaf.

Anyway, as every skill, it takes time to master, and digesting a lot of the available information. Contributing (don't fork gtk! that'd be useless) to such a project would require you an intermediate level of C.
There are many faces to programming in UNIX, but it is not *hard*. In my experience, it's really fun to learn how it all works: the ELF format, the stack, system calls, kernel and userspace.....
As for programming practices, don't get too worked up about it, just try to write your code correctly, which is at the end the most important thing.
It won't take you 'decades' per se, but mastery in anything is indeed a function of time. Write a lot of code, read a lot, and get out of /g/. Nobody ever should listen to /g/, that's the single worse thing a programmer can ever do. After all, it's a consumer technology board for /v/...
tl;dr just do it.

  No.19341

Hey guys! I was reading >>17892, and it's got me interested in livecoding. I think I'm going to try out Fluxus, an environment that someone mentioned in the thread; but that's purely off the recommendation of one person.

What are some other good/important livecoding environments? Is there anything someone new to livecoding ought to know?

  No.19346

If you are interested in music check out TidalCycles.

I kinda hate it, as a programmer, but it is very quick to get off the ground and make noise.

  No.19347

>>19346
a reply to >>19341, if it was not obvious

  No.19377

>>19346
Thanks for the tip! Although I do wonder, what makes you hate it "as a programmer?"

  No.19445

#include <stdio.h>

int main(){
long nc;

nc=0;
while (getchar() != EOF) {
++nc;
printf("%ld\n", nc);
}

}

Dumb K&R noob question here, when I run this program and input one character and hit return it outputs
#1 character input
1
2

Is that because Return/newline in itself is considered a char?

  No.19449


  No.19451

>>19445
what does \n do?
printf("%ld\n", nc);

  No.19452

>>19451
It's a special escape character. Stands for newline.
printf("%ld\n", nc); will print a number of type long (in this case the value nc), followed by a newline.

  No.19512

File: 1476899486137.png (58.91 KB, 106x200, interval.png)

I am going through sicp and I stack at the interval arithmetic's example.Can someone explain me that the heck is sum of the intervals? Sites only explains this as (x1,y1)+(x2,y2)=([x1+x2],[y1+y2]), that does it mean, and how does this relate to resistors in the chapter?

  No.19513

can anyone tell me what the code tags are? I cant get the usual [code] to work

  No.19520

>>19512
>someone explain me that the heck is sum of the intervals?
Straight from the horse's mouth:
https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-14.html#%_sec_2.1.4
"""Alyssa first writes a procedure for adding two intervals. She reasons that the minimum value the sum could be is the sum of the two lower bounds and the maximum value it could be is the sum of the two upper bounds"""

>how does this relate to resistors in the chapter?

"""Resistance values are usually known only up to some tolerance guaranteed by the manufacturer of the resistor. For example, if you buy a resistor labeled ``6.8 ohms with 10% tolerance'' you can only be sure that the resistor has a resistance between 6.8 - 0.68 = 6.12 and 6.8 + 0.68 = 7.48 ohms. Thus, if you have a 6.8-ohm 10% resistor in parallel with a 4.7-ohm 5% resistor, the resistance of the combination can range from about 2.58 ohms (if the two resistors are at the lower bounds) to about 2.97 ohms (if the two resistors are at the upper bounds)."""

>>19513
[ c o d e ]
...
[ / c o d e ]

without spaces

  No.19568

File: 1477130390190.png (42.88 KB, 200x43, sicp.png)

I can't get what should I do in this sicp's exercise.

  No.19569


  No.19570

>>19569
Thanks, but its an full answer, I just can't give up so easy, for me its not like school then I have to see the answers to pass homework and get mark, now I want to really understand things by myself

  No.19571

>>19570
The explanation in there is pretty good, you don't have to copy his methods, just use it as a bridge to clear what you're missing. It's what i usually do.

  No.19583

hi, im very new
Im using python, andwant to define a variable(or something that'll fill that role) that will change according to the values of other such variables without having to worry about the sequence in which the computer is reading instructions, and something having the wrong value because I got that sequence wrong.
what do? objects or something?

  No.19590

>>19583
Use "getters" and "setters" in OOP?

  No.19595

Is it really bad, that sometimes then I was stack on some exercises in sicp's chapter 1, I have looked answers in sicp-wiki? Now I feel like I will never be a programmer because I havent tried harder to solve a problem.

  No.19596

>>19595
If you take the time to understand the answer and write your own code, thats better than most, drawing conclusions from scratch is only better because your definitions will stick better in your head, and they won't be biased by the answers you read online. The important thing is to understand concepts, not to guess the right answer. Exercises are only a tool to help you reach the right conclusions, this isn't school, don't study as if it was.

  No.19601

What about HtDP? Is it good alternative for SICP?

  No.19605

>>19601
Nope
it's an introductory book aimed at high school students.
There's no reason to look for "alternatives to SICP".

  No.19606

>>19583
You really need to elaborate here. What you said doesn't make much sense.
IF what you mean is that you want a variable to update automatically so that whenever you read it it has the proper value or whatever, you should use a function instead, which computes the variable based on the current state of the program.

  No.19616

>>19605
> it's an introductory book aimed at high school students.
Well, sicp either

  No.19617

>>19605
If you're not having, if the mathematical content boggles your head, if the writing is like kicking dead whales down the beach for you, if it wasn't translated to your language and you're not that good at english, if you just don't like writing in LISP.

There are plenty of reason to want an alternative to SICP, it's a good book, it's not the only book on the same subject.

>>19601
There's a course in EDX called "Systematic coding", there's 3 parts and it deals similar subjects to SICP, i'm not sure if they have a book, but the course is quite on the same subject.

However this course is easy, insanely easy, in a way that was not productive to me, i felt like i was wasting my time after the first 2 weeks. I recommend doing the first week and then comparing to MIT'S SICP. Pick whichever one is more approachable to you.

Sadly i don't know any book to take the place of SICP, just experience really.

  No.19618

>>19617
I just noticed that HtDP is the course i was talking about, sorry. The argument stands though, if SICP isn't working for you sure go ahead, it's not the end of the world SICP isn't some holy grail, it's just better, but not as much as people will make you think. The purpose is the same, to deal with complexity. Both will help you, SICP gives you a more foundational knowledge that can be applied out of instinct, HtDP gives you a more straight forward path to follow.

Both work, both will boil down to instinct after you have some experience. SICP will just get you there a little faster because the exercises in the book are hard as fuarrrk, so you must learn before finishing the book.

  No.19659

I remember, in C, there was a way to get characters as soon as they're typed on the keyboard, ie not waiting until a newline is issued.
But I can't remember the name of it, I'd be grateful to whoever helps me with this.
Peace

  No.19662

>>19659
As far as I know there's no portable way of doing this.
You probably remember this: https://en.wikipedia.org/wiki/Conio.h

  No.19700

File: 1477501405917.png (219.38 KB, 200x117, 135238497859.png)

What is the practical usage of higher order procedures, lain? I'm going through SICP (course and book) and while i do understand how to use them, i can't think of a situation where they would be less complicated than just returning the processed values.

Why do you need a function to be passed as a parameter, and be returned as a value, when you can just use the final value that the function produces? Maybe i'm biased to think that the latter method is more simple, however i honestly cannot see a practical application of higher order procedures.

  No.19701

>>19700
Many
Callback functions are a common example. Say you have a tree-walking functionality, something that processes each node of a tree. If you wanted to perform a function on each node of the tree, the tree-walking would behave exactly the same, it would only differ on -what- it does with each node. For this to be simpler you can simply use a higher order function
(walk-tree tree (lambda (x) (display x)))
One real-world use of callback functions is actually in C, with libpcap, the packet sniffing library, which has a loop function that captures packets and takes a user defined function so that the user can decide what to do each time a packet is captured, without interrupting the loop or making the code too convoluted.
I suggest reading the second (iirc) chapter of Higher Order Perl, which deals particularly with this. No need to know Perl beforehand, it's readable enough.

  No.19702

>>19701
Thanks a lot lain.

  No.19737

How do I properly implement a dynamic linked list without using libraries?

  No.19749

>>19737
You've not given enough information to answer this particularly in-depth, such as language, but this is a simple question anyways.

A node has space for data or a pointer in the case of more general linked lists.
The only other piece of information a node has is the pointer to the next node.

So, allocate a node when you want and write procedures to modify them. If you would like to know some common operations performed on linked lists, look at a Lisp.

  No.19753

Does anyone have some basic resources for servers?
I want to create a homenetwork that i can access from the outside.
Getting a Pi soonish to start at a small level

  No.19781

https://github.com/ssloy/tinyrenderer/wiki

I've looked at this multiple times before, but every time I do I am confused as to how to go through this.
The author states to read it and implement alone, but then gives the code in the wiki anyways?? Doesn't that defeat the purpose?

Or maybe, is it supposed to be self-contained like a book? If so, what background knowledge am I supposed to have here to follow along?

  No.19877

File: 1477965422459.png (1.12 MB, 200x200, Dick_Grune,_Ceriel_J._H._Jacobs_Parsing_Techniques_A_Practical_Guide.pdf)

>>17745
>for example to parse html and build a dom tree.
I don't know what a dom tree is nor how it works, but if it is about parsing, you should read this book. If you wanna learn parsing theory from a mathematical point of view, you should read Sippu's Parsing Theory (both volumes).

  No.19891

So i've been learning C for almost a month now, and i'm still new to advanced topics and concepts, and i don't know where to look/what to look for anymore. I'm doing undergraduate research on rdma, but i'm still unsure what i'm actually doing. I did went through all of cs50's C lectures, and read Practical C Programming. After those I started making simple programs to learn and implement shared memory, message queues, semaphores, and pthreads. I also know some basic data structures(linked lists, binary trees, and i learn about hash tables recently in my data structures class, but haven't looked into implementations). Currently i'm just using C to go through the cryptopals problems to learn more about cryptography. I'm also considering learning 6502 assembly, and i'm currently in a course that is teaching me mips assembly. after these projects i'm going to pick up haskell and lisp(i'm thinking scheme rn). I'm also intrigued by hardware. I'm in my third electric engineering course, where we are learning avr assembly. I found a cool channel made by Ben Eater on youtube, and he has a lot of videos of him making everything for an 8 bit breadboard pc(making the registers, the ram, etc) and think it would be amazng if i could learn enough to build my own system (westell makes chips that use 6502, so i was thinking about using that for the cpu).
TL;DR i know a decent bit about programming and hardware, what should i learn/where should i look now?

  No.19893

is there a tech dictionary?

  No.19894

>>19893
This is the closest thing to what you're asking for: www.catb.org/jargon/

  No.20041

Hello, /lam/.
My intention is to have the best foundational knowledge i can get, so far what i've done is:

-CS50
-SICP
-Minor basic math books and courses, as i needed the math (basic math is something i'll review later on)

I'll write down what i plan to do from now on, at least in the next few months, it'd be very helpful if you could add/change some things. Material to study from is irrelevant, i'll find it when they become necessary.

What i'll currently do after SICP is:

-Algorithms course / book
-Functional programming course
-Object oriented programming course
-Debugging and testing course

After that i plan on making personal projects, maybe make some money as a freelancer and continue studying (less specific things like OS, databases, web dev, etc..).

Does this foundation lack anything? Besides practice of course.

  No.20044

Shouldnt this sticky be pinned?? By definition a sticky has to be pinned to be 'sticky', right?

  No.20045

>>20044
It is pinned. If you were using /mega/ it won't be fixed however.

  No.20055

I'm a beginner to compsci, I've been writing Python code for awhile, but have really only just began thinking about algorithms and actually about the code I'm writing as opposed to just writing code until it works.

I've been reading SICP and when my head hurts too much from it I go back to studying algorithms, how can I transfer the theory of their functions into a program? Say solving a maze with the A* Algorithm or even a number sorter, is it really just writing out the steps in the language or is there more to it than that?

I'm also confused on where to go from here, should I spend time sharpening my skills at coding and my understanding of algorithms or are their any real tangible paths to go to learn compsci?

  No.20059

>>20055
>is it really just writing out the steps in the language or is there more to it than that?
It gets fun when you start playing with implementation strategies, but generally my starting point when studying an algorithm is reading about it then doing a straightforward translation into an actual programming language.

Improving your understanding of algorithms by studying complexity theory and different techniques (I personally find functional programming to have a wealth of fun data structures, like finger trees or queue implementation strategies, etc) will do a lot for you if you're interested in computer science. "Computer science" is a pretty big field right now though, so what exactly you mean by that will change how relevant algorithms and data structures are. It won't hurt, though.

  No.20060

>>20055
By the way
>when my head hurts too much from it
That's a sign you're gaining a lot. Keep at it.

  No.20071

i try to restart services from a shell script
it doesnt work till i do manually

why?
is there a way of privilege escalation which allows me to run a clñean service restart without need to do it manually for it to work?

cmd:
/etc/init.d/networking restart
ifdown eth0; ifup eth0
service networking restart
etc...

any help?

  No.20073

>>20071
>is there a way of privilege escalation which allows me to run a clñean service restart without need to do it manually for it to work?

This is a question for the ages, m8, but the easiest (read: not best) answer
would be to run your whole script as root using sudo:

sudo myscript.sh


IIRC you should be able to edit your sudoers file to allow your user account
to run that script without a password.

Use the `visudo' command, then add a line that looks something like this:
my-user-name ALL=(ALL) NOPASSWD: /path/to/my/script/my-script-name

Definitely check your man pages, though; there is a solid chance that line
won't do what I think it does. It has been a while since I've had sudo on my
boxen.

  No.20074

>>20071
>>20073

if found it

"service networking restart" is not enough
a simple
"ifdown && ifup" did it for me thanks

the problem was i ran the script as root and tried to restart the network. got it right when i restarted from the terminal but nothing when i restarted it from the script.
it confused me as the terminal uses bash itself
well itseems there is something weird about restarting services cleanly in linux

  No.20076

>>20074
There is something weird about restarting services cleanly in Debian because it's a really shit and crufty distro with extreme bloat.
Besides, restarting the networking service isn't how you do it in Plebian anyway.

Real shame since there is no other real alternative to Debian and Debian derivatives for a 2-year cut release and support long after.

  No.20079

How can I make a simple C program to do RDMA send/receives and read/writes between a client and server that both have rdma cards? I'm lost right now on what to do with all of the different verbs out there, and I'm trying to understand how to write these kinds of programs so i can work on a bigger project that implements this

  No.20088

Did anyone here ever do http://www.aduni.org/courses/sicp/index.php?view=cw ?
How close to the contents of the book is it? How much of it does it cover? The first class and pset covers the first few chapters, but i'm not sure it's going all the way to the end of the book.

  No.20096

In catalog view of λ there is a missing slash in the title tag of the web page which you can see in the top window bar of your browser or in the tabs.

  No.20113

How do you realistically freelance as a programmer, lain? Considering i'm not into front end dev (i looked into it, but the range of requirements imply that i dive into web dev and study only that, which is not my thing).

  No.20115

>>20113
You pair with a frontend dev and a designer, pretty much. Unless it's something really simple you can do with a static site generator and bootstrap.

There's lots of people who want people to write scripts for them, usually VBA macros for excel or "report cleaning" scripts in python/perl/whatever.

  No.20179

When do you want a database?

  No.20185

heya lambda, never dove into coding before but I'm curious what AI learning/netsec is all about, where do I start?

  No.20189

I asked this on the /g/ programming thread but I'll ask it here since I'm even more uncertain based on the advice I received. I want to make a Python script that will generate a quake 3 arena config file (essentially a text file). Right now I'm having it take in CLI input, but I have a request for input for every option, i.e

# Player
playerName = input("seta name: ")
playerNick = input("seta nick: ")
playerHUD = input("seta ch_file: ")
# and so on

The player section is already give or take 6 input statements, and that's just the first section. Is this the most reasonable way to do this for CLI? I was told to use options/argparse, but I realized that if I had it all as one script, it would be a gigantic list of options and associated user input which would just defeat the point of having a script by making opening a text editor a better option.

  No.20192

How do you make a bit of extra money with programming? Most freelancing gigs i've seen all deal with web development/mostly front end and i'm not good at that.

  No.20194

>>20192
Make a wordpress plugin and sell it on Themeforest or make an app

  No.20198

>>20189
Options and input dara are two different things. Options control how your script performs its task; they should be arguments to the script and argparse is a good choice. Input data is what the script processes to produce useful output; in your case it should be in an input file, with an option to read stdin.

  No.20208

has this thread hit post limit?

  No.20209

>>20208
that answers that question.

  No.20213

Why are lisp-like languages so rare? God damn i'm finishing a course on SICP and i'm really sad to go back to C/C++, python is a little better but lisp feels just so comfy.
What i feel like is that i've been driving a tesla in germany while programming in scheme, and now going back to C i'll be driving an old pickup truck in India.
Not that C is bad as a language, of course not, it's just that i like the scope of lisp, i don't feel constrained by the language, while in C i still have to look at a reference book every now and then just to make sure i'm not fuarrrking something up. C++ is even worse, feels like a minefield. Wish i could work using lisp-ish languages, of course there's clojure but i live in a soykaf country ain't nobody going to hire a clojure programmer.

  No.20249

>>20123
>Why are lisp-like languages so rare?
Historical reasons - the original lisp tried to do things that were completely
insane at the time (for instance, garbage collection), which allowed other
languages (namely C) to overtake it.

Now that optimization is a thing, and hardware is ridiculously fast,
lisp has become a practical option, but now it's also got a couple decades
of history working against it.

  No.20323

Do you have any recommendations for freelancing work, lain? In the lines of freelancer.com

  No.20327

I was doing exercise 3.18 of sicp https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-22.html#%_thm_3.18
and i think that i finally did it, but im posting my solution here in case some lainon finds a list that can't be processed or makes my procedure return the wrong answer:

(define null nil)

(define (true? x)
(eq? x true))

(define (last-pair list-1)
(if (not (pair? (cdr list-1)))
list-1
(last-pair (cdr list-1))))

(define (append! main-list list-to-append)
(set-cdr! (last-pair main-list)
list-to-append)
main-list)

(define (eq-car-and-cdr? list-1)
(eq? (car list-1) (cdr list-1)))

(define (processed-pair? pair processed-pair-list)
(cond ((null? processed-pair-list) false)
((eq? pair (car processed-pair-list)) true)
(else (processed-pair? pair (cdr processed-pair-list)))))

(define (cycle? x)
(define processed-pair-list (list null))
(define true-false-list (list false))
(define (true-in-list? y)
(cond ((null? y) false)
((true? (car y)) true)
(else (true-in-list? (cdr y)))))
(define (cycle-helper z)
(cond ((not (pair? z)) true-false-list)
((processed-pair? z processed-pair-list) (append! true-false-list (list true null)))
(else (begin (append! processed-pair-list (cons z null))
(cycle-helper (car z))
(cycle-helper (cdr z))))))
(begin (cycle-helper x)
(true-in-list? true-false-list)))

-----------------------------------------------------------------------------

(define l1 (list 1 2 3))
(set-cdr! (last-pair l1) l1)

> (cycle? l1)

#t

(define z1 (list 1))
(define z2 (list 2))
(define z3 (list z1))
(set-cdr! z1 z2)
(set-cdr! z2 z3)
(set-car! z3 z1)

> (cycle? z1)

#t

  No.20358

Is the cost of a function call in C-based languages anything meaningful? Going through SICP is great and all, but when i go back to C code, my first instinct is to create small functions, for example if i have some "if" code with a double negative that isn't very readable, i'd like to encapsulate that check in a function, but is it worth it? To encapsulate a single line of code in a function, to improve readability and code management.
If i make similar changes for trivial code, will i be sacrificing far too much at some point?

  No.20359

>>20358
>Is the cost of a function call in C-based languages anything meaningful?
This is hard to say, with modern compilers such as GCC.

>Going through SICP is great and all, but when i go back to C code, my first instinct is to create small functions, for example if i have some "if" code with a double negative that isn't very readable, i'd like to encapsulate that check in a function, but is it worth it? To encapsulate a single line of code in a function, to improve readability and code management.

Read this, with John Carmack's viewpoint: https://archive.is/BE1ip

>If i make similar changes for trivial code, will i be sacrificing far too much at some point?

You're probably fine.

There's an old tale that Dennis Ritchie or Ken Thompson told people that C function calls were cheap and those same people later found that he'd lied and calls themselves were consuming around half of what the machine was doing. This is usually used as some story about virtue or some other such nonsense, but I find it wrong to lie about efficiency or in general and so see it more as another failure of the UNIX mindset more than anything.

If you'd like to see an example of an environment based around cheap procedure calls, look at Forth; the stack being used for arguments means that calls are simply single jump instructions, because there's nothing else to do.

  No.20371

>>20358
It depends on what you're doing, but usually function calls in C are expensive and it's not wise (or, efficient) to have too many function calls for simple stuff.
In regards to your question, it's a waste to use a function for a single line of code, or just a conditional. A branch may take about 5 cycles, (with just a single line of code inside), while a function call takes about 15 cycles. It doesn't improve readability either, it actually obscures it instead, having to deal with more and more function definitions.
But sometimes you may want to do it, in which case there is a keyword in C 'inline' which is a cue for the preprocessor to just write the definition instead of the function at preprocessor time.
/* Checks whether x is between a and b */
inline int inbetween(int a, int x, int b) {
return (x > a) && (x < b);
}

  No.20374

>>20371
Note that 'inline' is only a suggestion, not a requirement. Also compilers often inline non-'inline' functions anyway. Optimising code is a black art, and compilers tend to be much better at certain aspects of it than humans.

  No.20378

>>20374
welp, programmers shouldn't try to optimize needlessly, I ever only use stuff like inline functions for readability as I suggested above.

  No.20379

>>20327
A bit late because the powers that be frobbed the thread and it ceased bumping.

You are working on trees rather than lists, you are detecting undirected rather than directed cycles, and you do not short-circuit the computation as soon as the result is certain.

The exercise asks for lists and "taking successive cdrs", not trees where you also recurse into the car.

Your detection is undirected so it produces false positives which cannot go into infinite loops with c[ad]r calls. Consider a diamond shape of four elements with all links going down. This shape does not loop with c[ad]r calls, but your test flags it, because what you are really detecting is whether a node can be reached more than once in an exhaustive traversal. To detect c[ad]r cycles in trees you would need a dynamic visited list composed of the current node's ancestors.

As soon as you append the first true to true-false-list, the result will inevitably be true since true-in-list? is just an accumulation with or; further computation is redundant. The true-false-list is equivalent to a single boolean showing whether it contains a true.

And some minor points:
- Not all schemes have nil. You can define null as '() instead.
- There is no need for true? on a boolean, you can use it directly as the predicate of the cond clause.
- eq-car-and-cdr? is never used.
- Both procedure bodies and cond clauses are implicitly sequential, so the begins are not needed.
https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-20.html#footnote_Temp_323

  No.20380

>>20371
C inline is definitely not a preprocessor directive.
For one thing it would imply that inline functions could do all the text transform metaprogramming that #defines can do. It also would imply that the preprocessor understood the type system. I wish it was that sophisticated.

As said in >>20374, its a suggestion, that can be ignored in certain cases. With -finline-functions (implied by some optimization levels) GCC will inline things it thinks it is appropriate to anyway.

In general, let your optimization be guided by real profiling.

>>20378
So you find 'inline uint32_t func(uint32_t)' more readable than 'uint32_t func(uint32_t)'. I'm not sure how you could use inline functions for readability. Its just a keyword. Non-inline functions are just as readable.

  No.20470

Is there any keyword to search for the features of a language? What do i mean by that is something along the lines of "X language supports higher order procedures, Y language has pointers" etc.. When you go to a reference book you only have what the language does (syntax and libraries).
Looking for "features of language X" doesn't work either, by the way. You'll get subjective descriptions like "fast" and "reliable".

  No.20487

>>20470
being dead serious here: Wikipedia. if the language your interested in has a proper specification you can try and read that too.

  No.20497

>>20487
Strangely enough i didn't think of that, thankee.

  No.20533

>>20379

Yeah it's kind of hard to find this thread in the catalog. Anyways, i ended giving up with the exercise and investigating about it on the internet only to find an algorithm called "the tortoise and the hare" which was developed and investigated by a guy called Floyd on the '60, essentially, it moves two pointers forward at different speeds, it detects the cycle when those two pointers meet (they eventually do) and are equal to each other. I spent a day trying to solve the exercise with more complex prodecures, doing it all wrong and when i found the solution of Floyd which was very simple i felt kind of disappointed at myself ... but life goes on. Thanks for your attention, very appreciated.

  No.20572

What kind of books encompass machine code programming? I'm interested in compilers and this is a topic I have found little about... rather, I have no idea where to look for.

  No.20574

>>20572
This is a good one:
http://www.charlespetzold.com/code/

It builds from codes to switches to logic gates to circuits to programmable machines.

  No.20696

I'm a hobbiest programmer. I have a degree from a long time ago, but I am a teacher IRL. I applied to a python job and got an interview. Most of the work I do is in Perl and Lua. The job doesn't seem hard, it's basically just using some proprietary library under NDA to do web scrape on a large scale. I don't really know python, but I've played with it before, and it's the language that the job is in. Would I be best to spend the next two days playing with python and doing meaningless stuff, like practicing for programming problems (which I doubt there will be) or read the 300 page PDF about the library and try to build something with it so I can talk about it at the interview?

Am I dumb for not thinking python is something I should take seriously as a programmer? Maybe I am in the minority, but I think since I can code in C, and Perl, and sort-of lua, that python isn't the problem, and I can just catch up in a week if they want me to work for them?

  No.20697

>>20696
I'd say go with the library. I don't know if reading the pdf cavalier-style is the best approach though.
But doing something in the library will both give you experience with the language and the library. Your employer need someone who is apt for the job he's giving out so he will want someone who 1) knows how to program in python 2) knows how to make web scraps
3) preferably is acquainted with the library.
Also python is not an interesting language, it's syntax and semantics are very simple, and it has the "There is only one way to do it" philosophy which pretty much means go with the obvious approach. If you can speak computer you can speak python, so there's really nothing to learn.

  No.20714

>>20697
Thanks a lot lainon-- I got the job.

I feel like I have imposter syndrome, but I played with the library I built something to show the guy, and he didn't ask me any questions at all. I looked at all the code in the private repository, and the stuff is a bit complex--I dont' start for 2 weeks, so I guess now is the time to get deeply familiar with python.

  No.20757

>>20714
congratulations on that lainon!
If I may ask, where did you find the job? I'd like to get some freelance job with C or netadmin, but sites like freelance are always full of people usually with more credentials or more jobs finished under the platform, so I can't compete with that, being self taught and new to the site.

  No.20764

>>20757
Well I formally applied to a job interview I found on one of those job searching sites: indeed, monster, etc. I don't have a lot of experience, but I just advertised my work ethic, and I went into the job interview ready to be turned away--and offer to work for free in exchange for experience. It just turned out that the person hiring was hiring 70 new developers, and didn't care if I was the weakest link. I also had a portfolio on github full of projects I've messed around with, so when the intervieweer asked for my github, I could proudly show him. I actually made a new github that wasn't /cyber/ but still relatively private, in case that happened.


On the other hand, I have a lot of experience working on Upwork, and I dealt with the same thing you did, where indian programmers were willing to do the same thing I was for one dollar, and would do it better. In the end I was unsuccesful, but I also worked a full-time job the entire time, so I didn't have hours to compete like others did. Here were some of my ideas:
Do a few jobs that are simple for basically free; do some harder jobs for basically free, and try to get reviews for your work. Then you can start advertising your work ethic, and experience.

The other thing you can do, at least on upwork; Make another account with another name as someone looking to hire a person. Hire your self, and pay yourself, you lose 20% of the money spent, but you get the first job and you write yourself an amazing review.

  No.20767

>>20764
Thanks for all the advice anon!
Only...
> indian programmers were willing to do the same thing I was for one dollar, and would do it better
I sure hope a generic Indian can do a better job than me....

Anyway, I'll try doing `experience jobs' in the mean. Thanks again friend.

  No.20769

>>20767
s/can/cannot/

  No.20770

So I'm reading "Programming from the ground up" as recommended in Lainzine #2 but I've hit a problem with the Functions chapter. For some reason the assembler complains when I use AT&T syntax for pop and push instructions and only seems to accept Intel syntax for those two instructions only or a weird mix of both.

So: popl %eax complains about the suffix and the operand
pop eax gets accepted but then the linker complains that the register is undefined.

Other pop and pushes using immediate works like pop $2. If you use a suffix on that instruction the assembler also complains.

Is the book outdated? Was there a syntactic change? Or is the configuration for my assembler some how messed up?

  No.20771

>>20770
Sorry for the incomplete answer, but...
1. What assembler is it? nasm? as? gas?
2. Are you on a 64 bit system? The error is likely to happen because a 64 bit system is likely expecting %rax (the 64-bit version of %eax, though %eax is indeed supported by 64-bit, the linker is likely to work differently).
There should be a flag in your assembler to link a 32-bin binary (usually needs to be flagged as such in unix systems).
Most of your problems probably reduce to this, but if the syntax problem persists your assembler should have a flag for specifying that the source is written in AT&T syntax.

  No.20773

>>20771
It's gas, and yeah I realised the issue must be the fact it's a 64 bit system after posting. I didn't know about the 32-bit flag though, thanks for the help!

  No.20918

File: 1482165378547.png (11.13 KB, 200x28, 3.25 sicp.png)

Solved exercise 3.25 of sicp: https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-22.html#%_thm_3.25

Posting it in case someone finds an error or a better way to solve it:

(define (put content key-list table)
((table 'insert) key-list content))

(define (get key-list table)
((table 'lookup) key-list))

(define (show-table table)
(table 'show-table))

(define (make-table)
(let ((table (list '*table*)))

(define (assoc key records)
(cond ((null? records) false)
((equal? key (caar records)) (car records))
(else (assoc key (cdr records)))))

(define (last-key? key-list)
(if (null? (cdr key-list))
true
false))

(define (make-registry key-list content)
(if (last-key? key-list)
(cons (car key-list) content)
(cons (car key-list)
(list (make-registry (cdr key-list) content)))))

(define (insert! key-list content)
(define (insert!-helper key-list content table)
(let ((subtable (assoc (car key-list) (cdr table))))
(cond ((and subtable (last-key? key-list)) (set-cdr! subtable content))
(subtable (insert!-helper (cdr key-list) content subtable))
(else (set-cdr! table
(cons (make-registry key-list content)
(cdr table)))))))
(insert!-helper key-list content table))

(define (lookup key-list)
(define (lookup-helper key-list table)
(let ((subtable (assoc (car key-list) (cdr table))))
(cond ((null? key-list)
(error "lookup called with empty key list --- "key-list))
((false? subtable) "not found or doesn't exist in the table")
((and subtable (last-key? key-list)) (cdr subtable))
(else (lookup (cdr key-list) subtable)))))
(lookup-helper key-list table))

(define (false? q)
(equal? q false))

(define (dispatch m)
(cond ((eq? m 'lookup) lookup)
((eq? m 'insert) insert!)
((eq? m 'show-table) (display table))
(else (error "unknown operation -- table" m))))
dispatch))

---------------------------------------------------------------------------------
> (define tabla-prueba (make-table))
> (put 'zanahoria '(bag) tabla-prueba)
> (put 'lechuga '(second bag) tabla-prueba)
> (get '(bag) tabla-prueba)
'zanahoria
> (get '(second bag) tabla-prueba)
'lechuga
> (put 'elpulgas '(carpeta memes pavos) tabla-prueba)
> (put 'delao '(carpeta memes chimbos) tabla-prueba)
> (show-table tabla-prueba)
(*table* (carpeta (memes (chimbos . delao) (pavos . elpulgas))) (second (bag . lechuga)) (bag . zanahoria))
> (get '(carpeta memes pavos) tabla-prueba)
'elpulgas
> (get '(carpeta memes chimbos) tabla-prueba)
'delao
> (put 'nomemes '(carpeta) tabla-prueba)
> (get '(carpeta) tabla-prueba)
'nomemes
> (show-table tabla-prueba)
(*table* (carpeta . nomemes) (second (bag . lechuga)) (bag . zanahoria))

  No.20959

>>20918
The structure of the table and the overall intent of the code are both correct, the main problems are in lookup.

- The (null? key-list) test happens after (car key-list) has already been used in the assoc call, which is too late.
- The else branch uses lookup which does not take two arguments; should be lookup-helper instead.

And a few notes:
- The internal verbs of the table do not need the -table suffix (plain 'lookup and 'insert but 'show-table).
- In last-key? the null? test already provides the boolean you need, so there's little point in wrapping it in an if which acts as identity.
- In insert!-helper you didn't return a success token such as 'ok like the book prefers.
- In lookup, after the (false? subtable) case there's no point in using subtable in the and, since you know for certain that it will act as true; the and reduces to its second term.
- You could, if you wanted, allow both a value and branches in the same node, so that you could store values under both '(a b) and '(a b c) at the same time.

  No.20974

Can someone explain ruby blocks to me?

I kind of get the idea but I can't fathom when you would use them.

  No.20977

>>20974
Some Ruby methods are written to take blocks as arguments. If one of these Ruby methods is written with a block it'll use the block as a piece of code
# Times is a method that takes a block.
10.times { |i| puts i }
# If not given a block, times returns an array. Collect takes a block.
(1..10).c­ollect { |x| x * x }
# Collect is also called map.
(1.10).map { |x| x * x }
# There's also a reject/filter
(1..10).re­ject { |x| x % 2 == 0 }
Ruby blocks are used like anonymous functions are used in other languages.
# Word counter in Ruby
count = Hash.­new(0)
words.­split.each­ do
|word­| count­[word] += 1
end
;; Word counter in Common Lisp
(defvar *count* (make-hash-table #'test #'equal))
(mapcar (lambda (word)
(incf (gethash word *count* 0)))
(cl-ppcre:split "\\s+" "How are you?"))

  No.20978

>>20977
>If not given a block, times returns an array.
This is false.

  No.20990

>>20959

Made the corrections:

> - The (null? key-list) test happens after (car key-list) has already been used in the assoc call, which is too late.


> - The else branch uses lookup which does not take two arguments; should be lookup-helper instead.


> - In lookup, after the (false? subtable) case there's no point in using subtable in the and, since you know for certain that it will act as true; the and reduces to its second term.


(define (lookup key-list)
(define (lookup-helper key-list table)
(let ((subtable (assoc (car key-list) (cdr table))))
(cond ((false? subtable) "not found or doesn't exist in the table")
((last-key? key-list) (cdr subtable))
(else (lookup-helper (cdr key-list) subtable)))))
(if (null? key-list)
(error "lookup called with empty key list --- "key-list)
(lookup-helper key-list table)))

> - In last-key? the null? test already provides the boolean you need, so there's little point in wrapping it in an if which acts as identity.

I sometimes make the mistake of wrapping the boolean that test the truth of something inside a if, without realising.

(define (last-key? key-list)
(null? (cdr key-list)))

> - In insert!-helper you didn't return a success token such as 'ok like the book prefers.

(define (insert! key-list content)
(define (insert!-helper key-list content table)
(let ((subtable (assoc (car key-list) (cdr table))))
(cond ((and subtable (last-key? key-list)) (set-cdr! subtable content))
(subtable (insert!-helper (cdr key-list) content subtable))
(else (set-cdr! table
(cons (make-registry key-list content)
(cdr table)))))))
(insert!-helper key-list content table)
'ok)

> - You could, if you wanted, allow both a value and branches in the same node, so that you could store values under both '(a b) and '(a b c) at the same time.

Yeah i was thinking about that, the reason i didn't implement a make-table procedure that allows to store content inside diferent tables that have the same first-key, but the list of keys is not equal? was because it was a bit simpler to develop a make-table procedure like i did and when i make my procedures to solve the problems of the book i always tend to make them to their simplest "expression" and then i keep adding more complex things. Analogy: sort of like the way Sussman and Abelson explained the proccess of solving the Hanoi Towers problem, they reduced the problem to the most simplest "expression" (0 towers) and then they were adding more and more towers until they solved the problems for N quantity of towers.

what i didn't understand well:

> - The internal verbs of the table do not need the -table suffix (plain 'lookup and 'insert but 'show-table).


are you talking about these procedures?

(define (put content key-list table)
((table 'insert) key-list content))

(define (get key-list table)
((table 'lookup) key-list))

(define (show-table table)
(table 'show-table))

Also, thanks for your time.

  No.21013

>>20990
>are you talking about these procedures?
'show-table might as well be plain 'show since it's internal to make-table.

>(define (lookup key-list)

From its new position the (null? key-list) test becomes a one-time check that the caller didn't pass in an empty key-list. If that's what you want, that's fine, though it becomes curious why lookup would have it but not insert. However, my impression from its initial placement was that you were attempting to avoid partial lookups, where e.g. you insert under '(a b c d) then ask for '(a b) and get back a partial table on the (last-key? key-list) branch. This isn't wrong by itself, in some contexts it could be useful, but it exposes the table's internal structure and makes it part of its contract. Having 'show-table display the table rather than return it and have it printed by the repl further suggests that this wasn't desired.

  No.21034

>>21013

About the second note, yes, i forgot to put the same condition in the insert! procedure.

Anyways, i was solving the exercise 3.26 https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-22.html#%_thm_3.26 and i have a problem with it: the insert! procedure is not mutating the table, here's what i got so far:

(define (put content key-list table)
((table 'insert) key-list content))

(define (get key-list table)
((table 'lookup) key-list))

(define (show-table table)
(table 'show-table))

(define (make-table)
(let ((table '()))

(define (last-key? key-list)
(null? (cdr key-list)))

(define (make-registry key-list content)
(if (last-key? key-list)
(list (cons (car key-list) content) '() '())
(list (cons (car key-list)
(make-registry (cdr key-list) content))
'()
'())))

(define (left-branch record)
(cadr record))

(define (right-branch record)
(caddr record))

(define (node record)
(car record))

(define (node-key record)
(car (node record)))

(define (false? q)
(equal? q false))

(define (assoc key records)
(cond ((null? records) false)
((= key (node-key records)) (node records))
((< key (node-key records)) (assoc key (left-branch records)))
(else (assoc key (right-branch records)))))

(define (lookup key-list)
(define (lookup-helper key-list-h table)
(let ((subtable (assoc (car key-list-h) table)))
(cond ((false? subtable) "not found or doesn't exist")
((last-key? key-list-h) (cdr subtable))
((and subtable (last-key? key-list-h)) (cdr subtable))
((and subtable (not (last-key? key-list-h)))
(lookup-helper (cdr key-list-h) (cdr subtable)))
((< (car key-list-h) (node-key table))
(lookup-helper key-list-h (left-branch table)))
(else (lookup-helper key-list-h (right-branch table))))))
(lookup-helper key-list table))

(define (insert! key-list content)
(define (insert!-helper key-list-h table)
(let ((subtable (assoc (car key-list-h) table)))
(cond ((null? table)
(set! table (make-registry key-list-h content)))
((and subtable (last-key? key-list-h)) (set-cdr! subtable content))
((and subtable (not (last-key? key-list-h)))
(set-cdr! subtable (make-registry (cdr key-list-h) content)))
((< (car key-list-h) (node-key table))
(insert! key-list-h content (left-branch table)))
(else (insert!-helper key-list-h content (right-branch table))))))
(insert!-helper key-list table))

(define (dispatch m)
(cond ((eq? m 'lookup) lookup)
((eq? m 'insert) insert!)
((eq? m 'show-table) (display table))
(else (error "unknown operation -- table" m))))
dispatch))


--------------------------------------------------------------

> (define test-table (make-table))

> (put 'carrot '(1) test-table)
> (show-table test-table)
()

do you know what is the problem?

  No.21047

>>21034
The specific problem you are asking about is shadowing.
https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-21.html#%_idx_3060

>(define (insert!-helper key-list-h table)

[...]
> (set! table (make-registry key-list-h content)))

The table argument of insert!-helper hides the table variable from make-table's let. The set! assigns a new value to the former, which has no effect on the latter. You can add a (display table) right after the set! to see the new value.

The overall approach of the code, however, is no longer appropriate for binary trees. You don't need separate nodes and records, there are no lists of records anymore, and the table is simply the root node. You can take some inspiration from the Huffman section.

Also, make-table should take the equality and comparison tests as arguments at creation time rather than having them hardcoded as = and <.

  No.21056

I want to learn about parses and how they work. I just don't get them. Any introduction tutorials or textbook recommendations would be greatly appreciated.

  No.21057

>>21056
>I want to learn about parses and how they work. I just don't get them.
Parsers are simple.
>Any introduction tutorials or textbook recommendations would be greatly appreciated.
I'll explain some simple parsers to you, so you can get a good idea.

With Forth, and I'm explaining the basic idea rather than any idealized version, the parser is usually a procedure named word; this discards whitespace until it finds non-whitespace which it then collects until encountering more whitespace; the dictionary, a list of procedure names and their code, is consulted with a word usually called find and the address of this code is used in compilation; if the word isn't found, a word usually called >number is used to attempt to convert it to a number, which is used in compilation if successful; if all of this fails, you've an error.

Most languages do have more complex grammar, however, so I'll explain those a bit too. Most languages are based on keywords or punctuation, so the parser looks for these. When it sees one of these, it uses known rules for how to continue parsing. A language usually defines basic concepts and their shape, such as an expression.

Let's say an expression is anything that contains numbers, +, -, *, /, or name(), where name is a function name. So, when the parser finds VAR I = 1 + 2 it knows from VAR that it's declaring a variable and starts looking for, let's say, names, which it collects with whitespace delimiting. When it sees the =, it knows that the names have all been collected and looks for the expression, which it also already knows how to parse, just as it did with VAR. Then it has a variable named I that's set to 1 + 2; it simply transforms this to its internal representation, probably the number 3 and the name I being added to a table.

Really, it's nothing complex. My advice is to use a language with a simple grammar, so that it's easy to consider how the text is converted to a program. Languages such as Forth, Lisp, APL, and Prolog. A hallmark of some of these simple languages is the ability to define your own grammar rules and whatnot to play with.

  No.21059

>>21057
We'll, I get the basics. I can take a text input and tokenize it, using a lookup table to differentiate between symbols, identifiers and keywords. It's after tokenize that I'm lost... for instance if I want to write a json parser how would I go about it.

I'm familiar with c, java, ruby, swift and Haskell. Some of these languages even have parser libraries. However, I'm trying to build a parser from scratch so that I can better understand them.

  No.21060

I have been learning hacking for a couple of days. I already know programming, but I do not have much experience into low-level programming languages ( I only played around with assembly for a week and that was it ).
I was looking for a programming language that could help me understand how a system work in a lower level better than the high-level programming languages I already mess with, and having opportunity to work with it would be a big plus. After scanning some searches on google, it seemed to me that C++ might be the choice, the other ones that came into my mind was C and Assembly.

What do you guys think?

  No.21061

>>21060
C, Assembly and Forth are the ones you're looking for
It really depends on what you want to do, so you should do some research about them three before you choose to go head first into the language. Here are some tips
Assembly is helpful mostly for reverse engineering, trying to figure out the internals of a program for which you don't have the source. Also for debugging and finding flaws in the program. It is however hard to read and mantain (and port) a program written in assembly. It is strictly machine independent but also very simple (besides the particular idiosyncracies of the machine).
C is the language in which most software is written, including your OS, it's a high level, portable, etc. But it keeps very close to the machine, C++ is just C with stuff that takes you away from the machine. In learning C you'll learn some things about how programs are structured, how data is managed inside the program, etc. It's a bit challenging to learn some of the low level ideas (I learned assembly before C so I had no problem), but the core language is very small, as anything, it takes mostly practice to learn.
Some people call C "cross platform assembly language". I think Forth fits that better. Forth is not very much used in software development, rather, it is heavy on embedded systems (say, like the spyware in your car and TV, or in the processor of big radiotelescopes). It is very strange to the eyes of someone used to languages like C, but it is more straightforward than C in how things get done, and it's more flexible, it is also interactive meaning you don't have to compile a source file every time you find a problem in your code. I haven't used it much, but it seems to me that it is great for exploring interactively some low-level constructions. On the other hand, it's execution model is an idealized stack machine, and so it doesn't really map into what a process looks like in memory.

My suggestion would be
Assembly -> C -> Forth
if you want to do reverse engineering, bug hunting, exploitation, etc. If you're more interested in "the art of programming", you should probably swap C and Forth here.
Also don't master one then move on to the next one, learn the basics, practice for a couple weeks, then move on, but keep learning about the others. That'll make you a great low-level hacker.

  No.21062

hello everyone, i know absolutely nothing about programming, i am interested in learning about hacking.
can anyone tell me which languages i should learn first?
any good book or tutorials that can help me out in my quest?

  No.21063

>>21061
That was a really helpful post, anon.

The bit chunk of knowledge of assembly I have I got from "The programming from the ground up", which btw is a great book, After I complete that, there is something spcific I should read/focus?

Thanks anyway

  No.21064

File: 1482515981243.png (580.48 KB, 200x174, meditate.jpg)

>>21062
You're going to read <https://www.cs.cmu.edu/~dst/LispBook/book.pdf>

But first, you need a suitable environment for programming discovery; notably emacs. Read one of the `Getting Going with Common Lisp' articles depending on your OS: <http://cliki.net/Getting%20Started>. Then read <https://tuhdo.github.io/emacs-tutor.html>.

Report any issue on here or on #lisp or #emacs on irc.freenode.net (<https://freenode.net>)

Happy hacking.

  No.21065

>>21064
the first link does not work, can you provide another one?

  No.21066

>>21065
actually disregard that, none of the links work

  No.21067

>>21066
Sorry about that it was due to the use of the <>. Please remove them from the links. Apologies

  No.21069

File: 1482518550459.png (285.01 KB, 141x200, 1468971566437.jpg)

>>21067
now they work thank you very much good sir have a cute girl for your efforts